Subversion Repositories havirt

Rev

Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 41 Rev 42
Line 35... Line 35...
35
#
35
#
36
# v1.2.0 20240826 RWR
36
# v1.2.0 20240826 RWR
37
# Modified the flag structure to conform to standard (ie, dryrun instead of yes)
37
# Modified the flag structure to conform to standard (ie, dryrun instead of yes)
38
# Added a lot of 'verbose' print lines, and modified for new flag structure
38
# Added a lot of 'verbose' print lines, and modified for new flag structure
39
# Added a config file, which is auto-generated if it doesn't exist
39
# Added a config file, which is auto-generated if it doesn't exist
-
 
40
#
-
 
41
# v1.2.1 20250511 RWR
-
 
42
# changed so even if quiet set, if dryrun is set, will print what is returned from the called script
-
 
43
# Also, incorporates v1.3.0 on cluster.pm and v1.2.1 on havirt.pm
40
 
44
 
41
#use experimental "switch";
45
#use experimental "switch";
42
 
46
 
43
# requires File::Slurp. 
47
# requires File::Slurp. 
44
# In Debian derivatives
48
# In Debian derivatives
Line 92... Line 96...
92
   print "\t--force|f force an action, even if not normally done\n";
96
   print "\t--force|f force an action, even if not normally done\n";
93
   print "\t--target|-t NODE # the action use NODE for the target of actions\n";
97
   print "\t--target|-t NODE # the action use NODE for the target of actions\n";
94
   print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
98
   print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
95
   print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
99
   print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
96
   print "\t--quiet|q # do not print anything except major errors\n";
100
   print "\t--quiet|q # do not print anything except major errors\n";
-
 
101
   print "\t--verbose|v # increase verbosity of program. May be used multiple times\n";
97
}
102
}
98
 
103
 
99
&makeConfig( $config,$configFileName ) unless -f $configFileName;
104
&makeConfig( $config,$configFileName ) unless -f $configFileName;
100
$config = readConfig( $configFileName );
105
$config = readConfig( $configFileName );
101
 
106
 
Line 161... Line 166...
161
# new module.
166
# new module.
162
 
167
 
163
 
168
 
164
# we have to concat here since the double colon causes some interpretation problems
169
# we have to concat here since the double colon causes some interpretation problems
165
my $execute = $command . '::' . $action;
170
my $execute = $command . '::' . $action;
-
 
171
 
166
# load the module, die if it doesn't exist.
172
# load the module, die if it doesn't exist.
167
if (-f $config->{'script dir'} . "/$command.pm" ) {
173
if (-f $config->{'script dir'} . "/$command.pm" ) {
168
   require "$command.pm";
174
   require "$command.pm";
169
   Module->import( $command ); # for require, you must manually import
175
   Module->import( $command ); # for require, you must manually import
170
} else {
176
} else {
171
   die "Error, I don't know the command [$command]\n";
177
   die "Error, I don't know the command [$command]\n";
172
}
178
}
173
 
179
 
174
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
180
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
175
  my $message =  &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
181
  my $message =  &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
176
  print $message unless $main::config->{'flags'}->{'quiet'};
182
  print $message unless $main::config->{'flags'}->{'quiet'} && !$main::config->{'flags'}->{'dryrun'};
177
} else { # method $action does not exist in module $command, so just a brief error message
183
} else { # method $action does not exist in module $command, so just a brief error message
178
  die "Error, could not find action [$action] for module [$command]\n";
184
  die "Error, could not find action [$action] for module [$command]\n";
179
} 
185
} 
180
 
186
 
181
1;
187
1;