From 40cb22fb40e01f92fc4d7511e23ca1a3c21ae29c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 26 Nov 2008 18:56:00 +0100 Subject: pkg: Added commandline options No completion for now, though, since something does not quite work there --- bin/pkg | 23 ++++++++++++++++++++--- man/1/pkg | 32 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/bin/pkg b/bin/pkg index f1b1867..09c94af 100755 --- a/bin/pkg +++ b/bin/pkg @@ -70,6 +70,26 @@ if [[ -f $HOME/.pkg.conf ]] { export PDIR export PKG_ROOT +## +## commandline parsing +## + +# commandline options override everything else +while [[ $1 == [-+]* ]] { + case $1 in + -q|--quiet) SILENT=1 ;; + +q|--no-quiiet) SILENT=0 ;; + -au|--auto-update) AUTOUPDATE=1 ;; + +au|--no-auto-update) AUTOUPDATE=0 ;; + -co|--checklinks-options) CL_OPTIONS+=$1; shift ;; + -p|--packagedir) PDIR=$1; shift ;; + *) die "Unknown argument: '$1'\n" ;; + esac + shift +} + +action=$1 +shift ## ## Make sure everything's sane @@ -691,9 +711,6 @@ function pkg_log { # Note: # wrap foobar "$1" <- the "" are neccessary here, since $1 is optional (and therefore may be empty) - -action=$1 -shift case $action in add) pkg_add $* ;; delete) pkg_remove $* ;; diff --git a/man/1/pkg b/man/1/pkg index 7733692..a6dfe05 100644 --- a/man/1/pkg +++ b/man/1/pkg @@ -6,7 +6,7 @@ pkg - Package maintenance utility =head1 SYNOPSIS -B I [ I ] +B [I] I [I] =head1 DESCRIPTION @@ -81,6 +81,36 @@ If no argument is given, updates all installed packages =back +=head1 OPTIONS + +B accepts both long and short options. +Options marked as [boolean] may be negated, +the short options by using '+' instead of '-' as prefix (like '+au'), +the long options by prepending a 'no', like '--no-auto-update'. + +Options always override the configuration file and the environment variables. + +=over + +=item B<-q>, B<--quiet> [boolean] + +Enable quiet mode, don't print progress. Useful for scripting + +=item B<-au>, B<--auto-update> [boolean] + +Automatically update the package list before doing certain actions + +=item B<-co>, B<--checklinks-options> I