Skip to content
Snippets Groups Projects
Commit 212de418 authored by Moe Jette's avatar Moe Jette
Browse files

Add support for -V or --version command line options.

parent 89857b00
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,7 @@ static void _print_node (char *node_name, node_info_msg_t *node_info_ptr); ...@@ -89,6 +89,7 @@ static void _print_node (char *node_name, node_info_msg_t *node_info_ptr);
static void _print_node_list (char *node_list); static void _print_node_list (char *node_list);
static void _print_part (char *partition_name); static void _print_part (char *partition_name);
static void _print_step (char *job_step_id_str); static void _print_step (char *job_step_id_str);
static void _print_version( void );
static int _process_command (int argc, char *argv[]); static int _process_command (int argc, char *argv[]);
static void _update_it (int argc, char *argv[]); static void _update_it (int argc, char *argv[]);
static int _update_job (int argc, char *argv[]); static int _update_job (int argc, char *argv[]);
...@@ -103,13 +104,23 @@ main (int argc, char *argv[]) ...@@ -103,13 +104,23 @@ main (int argc, char *argv[])
char **input_fields; char **input_fields;
log_options_t opts = LOG_OPTS_STDERR_ONLY ; log_options_t opts = LOG_OPTS_STDERR_ONLY ;
int option_index;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"oneliner", 0, 0, 'o'},
{"quiet", 0, 0, 'q'},
{"verbose", 0, 0, 'v'},
{"version", 0, 0, 'V'},
};
command_name = argv[0]; command_name = argv[0];
exit_flag = 0; exit_flag = 0;
input_field_count = 0; input_field_count = 0;
quiet_flag = 0; quiet_flag = 0;
log_init("scontrol", opts, SYSLOG_FACILITY_DAEMON, NULL); log_init("scontrol", opts, SYSLOG_FACILITY_DAEMON, NULL);
while((opt_char = getopt(argc, argv, "hoqv")) != -1) { while((opt_char = getopt_long(argc, argv, "hoqvV",
long_options, &option_index)) != -1) {
if (opt_char == (int)'h') { if (opt_char == (int)'h') {
_usage (); _usage ();
exit(0); exit(0);
...@@ -120,6 +131,10 @@ main (int argc, char *argv[]) ...@@ -120,6 +131,10 @@ main (int argc, char *argv[])
quiet_flag = 1; quiet_flag = 1;
else if (opt_char == (int)'v') else if (opt_char == (int)'v')
quiet_flag = -1; quiet_flag = -1;
else if (opt_char == (int)'V') {
_print_version();
return 0;
}
else { else {
fprintf(stderr, "getopt error, returned %c", opt_char); fprintf(stderr, "getopt error, returned %c", opt_char);
return 1; return 1;
...@@ -155,6 +170,12 @@ main (int argc, char *argv[]) ...@@ -155,6 +170,12 @@ main (int argc, char *argv[])
exit (error_code); exit (error_code);
} }
static void _print_version(void)
{
printf("%s %s\n", PACKAGE, SLURM_VERSION);
}
#if !HAVE_READLINE #if !HAVE_READLINE
/* /*
* Alternative to readline if readline is not available * Alternative to readline if readline is not available
...@@ -1083,7 +1104,7 @@ _process_command (int argc, char *argv[]) ...@@ -1083,7 +1104,7 @@ _process_command (int argc, char *argv[])
"too many arguments for %s keyword\n", "too many arguments for %s keyword\n",
argv[0]); argv[0]);
} }
printf ("%s (%s %s)\n", command_name, PACKAGE, SLURM_VERSION); _print_version();
} }
else else
...@@ -1421,10 +1442,13 @@ _update_part (int argc, char *argv[]) ...@@ -1421,10 +1442,13 @@ _update_part (int argc, char *argv[])
void void
_usage () { _usage () {
printf ("\ printf ("\
scontrol [-q | -v] [<COMMAND>] \n\ scontrol [<OPTION>] [<COMMAND>] \n\
-o one-liner: put one record per line. \n\ Valid <COMMAND> values are: \n\
-q is equivalent to the keyword \"quiet\" described below. \n\ -h or --help: equivalent to \"help\" command \n\
-v is equivalent to the keyword \"verbose\" described below. \n\ -o or --oneliner: equivalent to \"oneliner\" command \n\
-q or --quiet: equivalent to \"quite\" command \n\
-v or --verbose: equivalent to \"verbose\" command \n\
-V or --version: equivalent to \"version\" command \n\
\n\ \n\
<keyword> may be omitted from the execute line and scontrol will execute \n\ <keyword> may be omitted from the execute line and scontrol will execute \n\
in interactive mode. It will process commands as entered until explicitly\n\ in interactive mode. It will process commands as entered until explicitly\n\
...@@ -1437,6 +1461,7 @@ scontrol [-q | -v] [<COMMAND>] \n\ ...@@ -1437,6 +1461,7 @@ scontrol [-q | -v] [<COMMAND>] \n\
their completing or down nodes \n\ their completing or down nodes \n\
exit terminate scontrol \n\ exit terminate scontrol \n\
help print this description of use. \n\ help print this description of use. \n\
oneliner report output one record per line. \n\
pid2jid <pid> return slurm job id for given pid. \n\ pid2jid <pid> return slurm job id for given pid. \n\
ping print status of slurmctld daemons. \n\ ping print status of slurmctld daemons. \n\
quiet print no messages other than error messages. \n\ quiet print no messages other than error messages. \n\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment