Skip to content

Commit

Permalink
tools/nutconf/nutconf-cli.cpp: add a version printout to Usage (both …
Browse files Browse the repository at this point in the history
…help and new standalone option) [#2573]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Aug 5, 2024
1 parent f7b41c4 commit 15163a5
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tools/nutconf/nutconf-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ class Usage {

public:

/** Print usage */
/** Print version and usage to stderr */
static void print(const std::string & bin);

/** Print version info to stdout */
static void printVersion(const std::string & bin);

}; // end of class usage


const char * Usage::s_text[] = {
" -h -help",
" --help Display this help and exit",
" -V",
" --version Display tool version on stdout and exit",
" --autoconfigure Perform automatic configuration",
" --is-configured Checks whether NUT is configured",
" --local <directory> Sets configuration directory",
Expand Down Expand Up @@ -167,9 +172,23 @@ const char * Usage::s_text[] = {
"",
};

/**
* Print version info to stdout (like other NUT tools)
*/
void Usage::printVersion(const std::string & bin) {
std::cout
<< "Network UPS Tools " << bin
<< " " << describe_NUT_VERSION_once() << std::endl;
}

/**
* Print help text (including version info) to stderr
*/
void Usage::print(const std::string & bin) {
std::cerr
<< "Network UPS Tools " << bin
<< " " << describe_NUT_VERSION_once() << std::endl
<< std::endl
<< "Usage: " << bin << " [OPTIONS]" << std::endl
<< std::endl
<< "OPTIONS:" << std::endl;
Expand Down Expand Up @@ -3100,6 +3119,13 @@ static int mainx(int argc, char * const argv[]) {
::exit(0);
}

// Usage
if (options.exists("version") || options.existsSingle("V")) {
Usage::printVersion(prog);

::exit(0);
}

// Check that command-line options validity
if (!options.valid) {
options.reportInvalid();
Expand Down

0 comments on commit 15163a5

Please sign in to comment.