From 9477aee2bc1e61af101396792e7f7d32e5e51c5a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 9 Jul 2013 00:50:14 -0600 Subject: librefetch: make the second argument optional, document --- src/librefetch/librefetch | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/librefetch/librefetch b/src/librefetch/librefetch index 368bfb4..3d37123 100755 --- a/src/librefetch/librefetch +++ b/src/librefetch/librefetch @@ -27,16 +27,30 @@ trap cleanup EXIT cmd=${0##*/} usage() { - print "Usage: %s [options] " "$cmd" + print "Usage: %s [options] []" "$cmd" print "Usage: %s -[g|V|h]" "$cmd" print "Downloads or creates a liberated source tarball." echo + print "The default mode is to create , first by trying download" + print "mode, then create mode." + echo + print "If isn't specified, it defaults to the non-directory" + print "part of , in the current directory." + echo + print "In download mode, the glob '*://' is stripped from the beginning of" + print ", and the resulting path is attempted to be downloaded" + print "from the configured mirror." + echo + print "In create mode, it looks at a build script, and uses that to create" + print "the source tarball. is ignored, except that it is used" + print "to set the default value of ." + echo print "The default build script is 'PKGBUILD', or 'SRCBUILD' if it exists." echo print "Unrecognized options are passed straight to makepkg." echo print "Example usage:" - print ' $ %s libre://mypackage-1.0.tar.gz $SRCDEST/mypackage-1.0.tar.gz.part' "$cmd" + print ' $ %s libre://mypackage-1.0.tar.gz' "$cmd" echo print "Options:" print " Settings:" @@ -106,13 +120,21 @@ main() { ######################################################################## - if [[ ${#extra_opts[@]} != 2 ]]; then - print "%s: %d non-flag arguments found, expected 2: %s" "$cmd" ${#extra_opts[@]} >> /dev/stderr - usage >> /dev/stderr - return 1 - fi - local src="${extra_opts[0]#*://}" - local dst="$(readlink -m "${extra_opts[1]}")" + local src dst + case ${#extra_opts[@]} in + 1) + src="${extra_opts[0]#*://}" + dst="$(readlink -m "${src##*/}")" + ;; + 2) + src="${extra_opts[0]#*://}" + dst="$(readlink -m "${extra_opts[1]}")" + ;; + *) + print "%s: %d non-flag arguments found, expected 1 or 2: %s" "$cmd" ${#extra_opts[@]} >> /dev/stderr + usage >> /dev/stderr + return 1 + esac # Mode: download ####################################################### -- cgit v1.2.2