cpt

Carbs Packaging Tools
git clone git://git.carbslinux.org/cpt
Log | Files | Refs | README | LICENSE

commit 14834b4e199bdd0cadea790083b1eb6f52dcaa14
parent 630a86dece64c9143a7a3dc65327fbbb818c9998
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu, 20 Aug 2020 14:47:17 +0300

cpt: use 'getopt' for option parsing

Diffstat:
Msrc/cpt-build | 20+++++++++++++++-----
Msrc/cpt-install | 16++++++++--------
Msrc/cpt-remove | 11+++++------
Msrc/cpt-search | 24++++++++++++++----------
Msrc/cpt-update | 15+++++++++------
5 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/src/cpt-build b/src/cpt-build @@ -4,11 +4,21 @@ # shellcheck disable=1091 if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi -case "$1" in - '') set -- "${PWD##*/}"; export CPT_PATH=${PWD%/*}:$CPT_PATH ;; - --help|-h) out "usage: ${0##*/} [pkg...]"; exit 1 ;; - --version|-v) version ;; -esac +eval set -- "$(getopt -l no-prompt,version,help -- yvh "$@")" +while :; do + case "$1" in + --help|-h) + out "usage: ${0##*/} [pkg...]" "" \ + " Options:" \ + " -y --no-prompt Do not prompt for confirmation" \ + exit 1 ;; + --version|-v) version ;; + --no-prompt|-y) export CPT_PROMPT=0; shift ;; + --) shift; break ;; + esac +done + +[ "$1" ] || set -- "${PWD##*/}"; export CPT_PATH=${PWD%/*}:$CPT_PATH create_cache diff --git a/src/cpt-install b/src/cpt-install @@ -4,21 +4,21 @@ # shellcheck disable=1091 if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi -while [ "$1" ]; do +eval set -- "$(getopt -l help,version,force,root: -- fhv "$@")" + +while :; do case "$1" in --help|-h) out "usage: ${0##*/} [options] [pkg...]" "" \ " Options:" \ - " --force Force installation" \ + " -f --force Force installation" \ " --root [rootdir] Use an alternate root directory" "" exit 1 ;; - --version|-v) version ;; - --force) export CPT_FORCE=1 ;; - --root) export CPT_ROOT=$2; shift 2 ;; - --) break ;; - -*) die "Unknown argument '$1'" ;; - *) break ;; + --version|-v) version ;; + -f|--force) export CPT_FORCE=1; shift ;; + --root) export CPT_ROOT=$2; shift 2 ;; + --) shift; break ;; esac done diff --git a/src/cpt-remove b/src/cpt-remove @@ -4,7 +4,8 @@ # shellcheck disable=1091 if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi -while [ "$1" ]; do +eval set -- "$(getopt -l help,version,force,root: -- fhv "$@")" +while :; do case "$1" in --help|-h) out "usage: ${0##*/} [options] [pkg...]" "" \ @@ -13,12 +14,10 @@ while [ "$1" ]; do " --root [rootdir] Use an alternate root directory" "" exit 1 ;; - --version|-v) version ;; - --force) export CPT_FORCE=1; shift ;; + -v|--version) version ;; + -f|--force) export CPT_FORCE=1; shift ;; --root) export CPT_ROOT=$2; shift 2 ;; - --) break ;; - -*) die "Unknown argument '$1'" ;; - *) break ;; + --) shift; break ;; esac done diff --git a/src/cpt-search b/src/cpt-search @@ -8,15 +8,19 @@ if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi # in order to only find the first instance of a package. all=1 -case "$1" in - --help|-h|'') - out "usage: ${0##*/} [--single] [pkg...]" "" \ - " Options:" \ - " --single Only show the first instance of a package" "" - exit 0 - ;; - --version|-v) version ;; - --single) unset all; shift ;; -esac +eval set -- "$(getopt -l single,version,help -- shv "$@")" +while :; do + case "$1" in + --help|-h|'') + out "usage: ${0##*/} [--single] [pkg...]" "" \ + " Options:" \ + " -s --single Only show the first instance of a package" "" + exit 0 + ;; + --version|-v) version ;; + --single|-s) unset all; shift ;; + --) shift; break ;; + esac +done for pkg; do pkg_find "$pkg" "${all:+all}"; done diff --git a/src/cpt-update b/src/cpt-update @@ -4,21 +4,24 @@ # shellcheck disable=1091 if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi -while [ "$1" ]; do +eval set -- "$(getopt -l no-fetch,download,root:,help,version,no-prompt -- yndhv "$@")" +while :; do case "$1" in --help|-h) out "usage: ${0##*/} [options]" "" \ " Options:" \ " -d --download Only download updatable packages" \ - " --no-fetch Do not refresh the repositories" \ + " -n --no-fetch Do not refresh the repositories" \ + " -y --no-prompt Do not prompt for confirmation" \ " --root [rootdir] Use an alternate root directory" "" exit 1 ;; --version|-v) version ;; - --no-fetch) export CPT_FETCH=0; shift ;; - --root) export CPT_ROOT=$2; shift 2 ;; - --download|-d) export download_only=1; shift ;; - *) die "Unknown option '$1'" ;; + -d|--download) export download_only=1; shift ;; + -n|--no-fetch) export CPT_FETCH=0; shift ;; + -y|--no-prompt) CPT_PROMPT=0; shift ;; + --root) export CPT_ROOT=$2; shift 2 ;; + --) shift; break ;; esac done