diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-04-18 01:23:15 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-04-22 05:43:52 +0200 |
commit | fa5484c81c40e0a5a05194909600716f39ce0faf (patch) | |
tree | 8d83ec1e2a9dd68e4031696008a24f14a00512d5 | |
parent | 5d62de59adfa8e6b7c19c418effc8757637c702e (diff) | |
download | mkinitcpio-fa5484c81c40e0a5a05194909600716f39ce0faf.tar.gz mkinitcpio-fa5484c81c40e0a5a05194909600716f39ce0faf.tar.xz |
mkinitcpio: adopt parseopts for option parsing
Updates the doc and bash-completion, as well. Also adds the previously
unmentioned -A option to the --help output.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r-- | bash-completion | 33 | ||||
-rwxr-xr-x | mkinitcpio | 152 | ||||
-rw-r--r-- | mkinitcpio.8.txt | 32 |
3 files changed, 132 insertions, 85 deletions
diff --git a/bash-completion b/bash-completion index b7fc277..f4c476b 100644 --- a/bash-completion +++ b/bash-completion @@ -32,18 +32,29 @@ _find_kernel_versions() { } _mkinitcpio() { - local action cur prev - action="-A -b -c -g -H -h -k -L -M -n -p -S -s -v -z" + local action cur prev opts + opts=(-A --add -b --basedir -c --config -g --generate -H --hookhelp + -h --help -k --kernel -L --listhooks -M --automods -n --nocolor + -p --preset -S --skiphooks -s --save -t --builddir -v --verbose + -z --compress) + _get_comp_words_by_ref cur prev - case "$prev" in - -c|-g) _filedir;; - -k) _find_kernel_versions;; - -b) _filedir -d;; - -p) COMPREPLY=($(cd /etc/mkinitcpio.d/ && compgen -X '!*.preset' -f -- $cur)) - COMPREPLY=("${COMPREPLY[@]%.preset}");; - -A|-H|-S) COMPREPLY=($(cd /lib/initcpio/install/ && compgen -f -- $cur) \ - $(cd /usr/lib/initcpio/install/ && compgen -f -- $cur));; - *) COMPREPLY=($(compgen -W "${action}" -- "$cur"));; + + case $prev in + -[cg]|--config|--generate) + _filedir ;; + -k|--kernel) + _find_kernel_versions ;; + -[bt]|--basedir|--builddir) + _filedir -d ;; + -p|--preset) + COMPREPLY=($(cd /etc/mkinitcpio.d/ && compgen -X '!*.preset' -f -- $cur)) + COMPREPLY=("${COMPREPLY[@]%.preset}") ;; + -[AHS]|--add|--hookhelp|--skiphooks) + COMPREPLY=($(cd /lib/initcpio/install/ && compgen -f -- $cur) + $(cd /usr/lib/initcpio/install/ && compgen -f -- $cur)) ;; + *) + COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur")) ;; esac } @@ -41,21 +41,22 @@ mkinitcpio $version usage: ${0##*/} [options] Options: - -b BASEDIR Use BASEDIR. default: / - -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf - -g IMAGE Generate a cpio image as IMAGE. default: no - -H HOOKNAME Output help for hook 'HOOKNAME'. - -h Display this message. - -k KERNELVERSION Use KERNELVERSION. default: $(uname -r) - -L List all available hooks. - -M Display modules found via autodetection. - -n Disable colorized output messages. - -p PRESET Build specified preset from /etc/mkinitcpio.d - -S SKIPHOOKS Skip SKIPHOOKS (comma-separated) when building the image. - -s Save build directory. default: no - -t DIR Use DIR as the temporary build directory. - -v Verbose output. Default: no. - -z COMPRESS Use COMPRESS on resulting image + -A, --add <hooks> Add specified hooks, comma separated, to image + -b, --basedir <dir> Use alternate base directory. (default: /) + -c, --config <config> Use alternate config file. (default: /etc/mkinitcpio.conf) + -g, --generate <path> Generate cpio image and write to specified path + -H, --hookhelp <hookname> Display help for given hook and exit + -h, --help Display this message and exit + -k, --kernel <kernelver> Use specified kernel version (default: $(uname -r)) + -L, --listhooks List all available hooks + -M, --automods Display modules found via autodetection + -n, --nocolor Disable colorized output messages + -p, --preset <file> Build specified preset from /etc/mkinitcpio.d + -S, --skiphooks <hooks> Skip specified hooks, comma-separated, during build + -s, --save Save build directory. (default: no) + -t, --builddir <dir> Use DIR as the temporary build directory + -v, --verbose Verbose output (default: no) + -z, --compress <program> Use an alternate compressor on the image EOF cleanup 1 @@ -109,51 +110,86 @@ get_kernver() { trap 'cleanup 130' INT trap 'cleanup 143' TERM -while getopts ':A:c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do - case $arg in - A) IFS=, read -r -a add <<< "$OPTARG" - ADDHOOKS+=("${add[@]}") - unset add ;; - c) CONFIG=$OPTARG ;; - k) optkver=$OPTARG ;; - s) SAVELIST=1 ;; - b) BASEDIR=$OPTARG ;; - g) GENIMG=$OPTARG ;; - h) usage ;; - p) PRESET=$OPTARG ;; - n) COLOR=0 ;; - v) QUIET=0 ;; - S) IFS=, read -r -a skip <<< "$OPTARG" - SKIPHOOKS+=("${skip[@]}") - unset skip ;; - H) if script=$(find_in_dirs "$OPTARG" "${INSTDIR[@]}"); then - . "$script" - if [[ $(type -t help) != function ]]; then - error "No help for hook $OPTARG" - exit 1 - fi - else - error "No hook '$OPTARG'" - exit 1 - fi - msg "Help for hook '$OPTARG':" - help - exit 0 ;; - L) msg "Available hooks" - for dir in "${INSTDIR[@]}"; do - ( cd "$dir" >/dev/null; printf ' %s\n' * ) - done | column -c$(tput cols) - exit 0 ;; - M) SHOW_AUTOMODS=1 ;; - t) TMPDIR=$OPTARG ;; - z) optcompress=$OPTARG ;; - :) error "option requires an argument -- '$OPTARG' (use -h for help)" - exit 1 ;; - \?) error "invalid option -- '$OPTARG' (use -h for help)" - exit 1 ;; +OPT_SHORT='A:b:c:g:H:hk:mnLMp:S:st:vz:' +OPT_LONG=('add:' 'basedir:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks' + 'automods' 'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:') + +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case $1 in + -A|--add) + shift + IFS=, read -r -a add <<< "$1" + ADDHOOKS+=("${add[@]}") + unset add ;; + -c|--config) + shift + CONFIG=$1 ;; + -k|--kernel) + shift + optkver=$1 ;; + -s|--save) + SAVELIST=1 ;; + -b|--basedir) + shift + BASEDIR=$1 ;; + -g|--generate) + shift + GENIMG=$1 ;; + -h|--help) + usage ;; + -p|--preset) + shift + PRESET=$1 ;; + -n|--nocolor) + COLOR=0 ;; + -v|--verbose) + QUIET=0 ;; + -S|--skiphooks) + shift + IFS=, read -r -a skip <<< "$1" + SKIPHOOKS+=("${skip[@]}") + unset skip ;; + -H|--hookhelp) + shift + if script=$(find_in_dirs "$1" "${INSTDIR[@]}"); then + . "$script" + if [[ $(type -t help) != function ]]; then + error "No help for hook $1" + exit 1 + fi + else + error "No hook '$1'" + exit 1 + fi + msg "Help for hook '$1':" + help + exit 0 ;; + -L|--listhooks) + msg "Available hooks" + for dir in "${INSTDIR[@]}"; do + ( cd "$dir" >/dev/null; printf ' %s\n' * ) + done | column -c$(tput cols) + exit 0 ;; + -M|--automods) + SHOW_AUTOMODS=1 ;; + -t|--builddir) + shift + TMPDIR=$1 ;; + -z|--compress) + shift + optcompress=$1 ;; + --) + shift + break 2 ;; esac + shift done -shift $((OPTIND - 1)) if [[ -t 1 ]] && (( COLOR )); then # prefer terminal safe colored and bold text when tput is supported diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt index 2b45f3b..10076a8 100644 --- a/mkinitcpio.8.txt +++ b/mkinitcpio.8.txt @@ -24,68 +24,68 @@ other features. Options ------- -*-A* 'hooks':: +*-A, \--add* 'hooks':: Add the additional 'hooks' to the image. These will be processed in order after all other hooks from the config file. Multiple hooks should be comma-separated. This option can be specified multiple times. -*-b* 'basedir':: +*-b, \--basedir* 'basedir':: Use 'basedir' as a starting point for gathering information about the currently running system. Default: /. -*-c* 'config':: +*-c, \--config* 'config':: Use 'config' file to generate the ramdisk. Default: /etc/mkinitcpio.conf -*-g* 'filename':: +*-g, \--generate* 'filename':: Generate a CPIO image as 'filename'. Default: no; this means nothing will be written to the filesystem unless this option is specified. -*-H* 'hookname':: +*-H, \--hookhelp* 'hookname':: Output help for hookname 'hookname'. -*-h*:: +*-h, \--help*:: Output a short overview of available command-line switches. -*-k* 'kernelversion':: +*-k, \--kernel* 'kernelversion':: Use 'kernelversion', instead of the current running kernel. This may be a path to a kernel image or a specific kernel version. If specified as a path to an image, this will always be prefixed by the 'basedir'. -*-L*:: +*-L, \--listhooks*:: List all available hooks. -*-M*:: +*-M, \--automods*:: Display modules found via autodetection. mkinitcpio will automatically try to determine which kernel modules are needed to start your computer. This option lists which modules were detected. -*-n*:: +*-n, \--nocolor*:: Disable color output. -*-p* 'preset':: +*-p, \--preset* 'preset':: Build initramfs image(s) according to specified 'preset'. This may be a file in /etc/mkinitcpio.d (without the .preset extension) or a full, absolute path to a file. -*-S* 'hooks':: +*-S, \--skiphooks* 'hooks':: Skip 'hooks' when generating the image. Multiple hooks should be comma-separated. This option can be specified multiple times. -*-s*:: +*-s, \--save*:: Saves the build directory for the initial ramdisk. Default: no; This means the directory will not be retained if this option isn't specified. Useful for debugging purposes. -*-t* 'tmpdir':: +*-t, \--builddir* 'tmpdir':: Use 'tmpdir' as the temporary build directory instead of /tmp. 'tmpdir' must exist. The 'TMPDIR' environment variable is also honored to set this location, but the command line option will take precedence. -*-v*:: +*-v, \--verbose*:: Verbose output. Outputs more information about what's happening during creation of the ramdisk. -*-z* 'compress':: +*-z, \--compress* 'compress':: Override the compression method with the 'compress' program. About Hooks |