Add short option to --version argument

Passing `--version=short` simply prints the version and exits.  This
will make it possible for a future commit to change `configure.ac` to
extract the version string from `ddclient.in` to avoid maintaining the
same version string in two places.
This commit is contained in:
Richard Hansen 2024-03-06 22:55:31 -08:00
parent 5eb6a6d755
commit c9cec591f0

View file

@ -1007,6 +1007,17 @@ $opt{'list-web-services'} = sub {
printf("%s %s\n", $_, $builtinweb{$_}{url}) for sort(keys(%builtinweb)); printf("%s %s\n", $_, $builtinweb{$_}{url}) for sort(keys(%builtinweb));
exit(0); exit(0);
}; };
$opt{'version'} = sub {
my (undef, $arg) = @_;
if ($arg eq "short") {
print("$version\n");
} else {
print("$program version $version\n");
print(" originally written by Paul Burry, paul+ddclient\@burry.ca\n");
print(" project now maintained on https://github.com/ddclient/ddclient\n");
}
exit(0);
};
my @opt = ( my @opt = (
"usage: ${program} [options]", "usage: ${program} [options]",
@ -1089,7 +1100,7 @@ my @opt = (
["verbose", "!", "--{no}verbose : print {no} verbose information"], ["verbose", "!", "--{no}verbose : print {no} verbose information"],
["quiet", "!", "--{no}quiet : print {no} messages for unnecessary updates"], ["quiet", "!", "--{no}quiet : print {no} messages for unnecessary updates"],
["help", "", "--help : display this message and exit"], ["help", "", "--help : display this message and exit"],
["version", "", "--version : display version information and exit"], ["version", ":s", "--version[=short] : display version information and exit"],
["postscript", "", "--postscript : script to run after updating ddclient, has new IP as param"], ["postscript", "", "--postscript : script to run after updating ddclient, has new IP as param"],
["query", "!", "--{no}query : print {no} ip addresses and exit"], ["query", "!", "--{no}query : print {no} ip addresses and exit"],
["fw-banlocal", "!", ""], ## deprecated ["fw-banlocal", "!", ""], ## deprecated
@ -1099,10 +1110,6 @@ my @opt = (
["redirect", "=i", "--redirect=<max> : enable and follow at most <max> HTTP 30x redirections"], ["redirect", "=i", "--redirect=<max> : enable and follow at most <max> HTTP 30x redirections"],
"", "",
nic_examples(), nic_examples(),
# Note: These lines are copied below to the -version argument implementation
"$program version $version",
" originally written by Paul Burry, paul+ddclient\@burry.ca",
" project now maintained on https://github.com/ddclient/ddclient"
); );
sub main { sub main {
@ -1116,15 +1123,7 @@ sub main {
if (opt('help')) { if (opt('help')) {
printf "%s\n", $opt_usage; printf "%s\n", $opt_usage;
exit 0; $opt{'version'}('', '');
}
if (opt('version')) {
# Note: Manual copy from the @opt array above!
print "$program version $version\n";
print " originally written by Paul Burry, paul+ddclient\@burry.ca\n";
print " project now maintained on https://github.com/ddclient/ddclient\n";
exit 0;
} }
## read config file because 'daemon' mode may be defined there. ## read config file because 'daemon' mode may be defined there.