Skip to content

Commit

Permalink
add -V, --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
falconindy committed Oct 27, 2012
1 parent 9e5ddcb commit 7597dd6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions extra/bash-completion
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ _pkgfile() {
_get_comp_words_by_ref cur prev _get_comp_words_by_ref cur prev


opts="-l --list -s --search -u --update -b --binaries -g --glob -i opts="-l --list -s --search -u --update -b --binaries -g --glob -i
--ignorecase -q --quiet -R --repo -r --regex -h --help -v --verbose --ignorecase -q --quiet -R --repo -r --regex -h --help -V --version
-w --raw -z --compress" -v --verbose -w --raw -z --compress"


if [[ $prev = -*R || $prev = '--repo' ]]; then if [[ $prev = -*R || $prev = '--repo' ]]; then
repos=$(sed '/^\[\(.*\)\]$/!d;s//\1/g;/options/d' /etc/pacman.conf) repos=$(sed '/^\[\(.*\)\]$/!d;s//\1/g;/options/d' /etc/pacman.conf)
Expand Down
2 changes: 2 additions & 0 deletions extra/zsh-completion
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ _longopts=(
'--quiet[output less when listing]' '--quiet[output less when listing]'
'--repo[search a specific repo]: :_repos' '--repo[search a specific repo]: :_repos'
'--regex[enable matching with regular expressions]' '--regex[enable matching with regular expressions]'
'--version[display program version]'
'--verbose[output more]' '--verbose[output more]'
'--raw[disable output justification]' '--raw[disable output justification]'
'--null[null terminate output]' '--null[null terminate output]'
Expand All @@ -51,6 +52,7 @@ _shortopts=(
'*-q[output less when listing]' '*-q[output less when listing]'
'*-R[search a specific repo]: :_repos' '*-R[search a specific repo]: :_repos'
'*-r[enable matching with regular expressions]' '*-r[enable matching with regular expressions]'
'*-V[display program version]'
'*-v[output more]' '*-v[output more]'
'*-w[disable output justification]' '*-w[disable output justification]'
'*-0[null terminate output]' '*-0[null terminate output]'
Expand Down
14 changes: 12 additions & 2 deletions src/pkgfile.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -426,14 +426,20 @@ static void usage(void)
stdout); stdout);
fputs( fputs(
" General:\n" " General:\n"
" -h, --help display this help and exit\n\n", " -h, --help display this help and exit\n"
" -V, --version display the version and exit\n\n",
stdout); stdout);
} }


static void print_version(void)
{
fputs(PACKAGE_NAME " v" PACKAGE_VERSION "\n", stdout);
}

static int parse_opts(int argc, char **argv) static int parse_opts(int argc, char **argv)
{ {
int opt; int opt;
static const char *shortopts = "0bdghilqR:rsuvwz::"; static const char *shortopts = "0bdghilqR:rsuVvwz::";
static const struct option longopts[] = { static const struct option longopts[] = {
{"binaries", no_argument, 0, 'b'}, {"binaries", no_argument, 0, 'b'},
{"compress", optional_argument, 0, 'z'}, {"compress", optional_argument, 0, 'z'},
Expand All @@ -447,6 +453,7 @@ static int parse_opts(int argc, char **argv)
{"regex", no_argument, 0, 'r'}, {"regex", no_argument, 0, 'r'},
{"search", no_argument, 0, 's'}, {"search", no_argument, 0, 's'},
{"update", no_argument, 0, 'u'}, {"update", no_argument, 0, 'u'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'}, {"verbose", no_argument, 0, 'v'},
{"raw", no_argument, 0, 'w'}, {"raw", no_argument, 0, 'w'},
{"null", no_argument, 0, '0'}, {"null", no_argument, 0, '0'},
Expand Down Expand Up @@ -509,6 +516,9 @@ static int parse_opts(int argc, char **argv)
case 'u': case 'u':
config.doupdate++; config.doupdate++;
break; break;
case 'V':
print_version();
exit(EXIT_SUCCESS);
case 'v': case 'v':
config.verbose = true; config.verbose = true;
break; break;
Expand Down

0 comments on commit 7597dd6

Please sign in to comment.