From 61dd6f1a768f95f031bc7ad22b1ab76476ba8bb6 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 4 Jul 2022 13:51:24 +0200 Subject: [PATCH] fix: document exit codes and flags --- instalee | 26 +++++++++++++++----------- instalee.1 | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 15 deletions(-) mode change 100644 => 100755 instalee diff --git a/instalee b/instalee old mode 100644 new mode 100755 index 1020902..2cdf80b --- a/instalee +++ b/instalee @@ -1,6 +1,7 @@ #!/bin/sh -home="${INSTALEE_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/instalee}" +name="$(basename "$0")" +home="$(find "$INSTALEE_HOME" "${XDG_CONFIG_HOME:-$HOME/.config}/$name" "$HOME/.$name" "$PWD" -maxdepth 0 2>/dev/null | head -1)" underline() { echo "$1"; } @@ -9,27 +10,30 @@ getcontent() { test -x "$1" && "$1" || cat "$1"; } # Get available package entries for given package get() { - result="$(cat "$home/handlers.available" | while read handler + cat "$home/handlers.available" | while read handler do find "$home/packages/$1" -name "$handler*" 2>/dev/null - done)" - test ! "$result" && echo "No handler for package '$1'" >>/dev/stderr && exit 1 - echo "$result" + done } - case "$1" in - (--version) - printf "instalee r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + (--version|"") + printf "$0 r%s.%s\n" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + echo "Try '$0 --help' or 'man $name' for usage info" # TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion ;; + (-?|-h|--help) + man $name 2>/dev/null || man "$home/$name.1";; (-a|--add) dir="$home/packages/$2" mkdir -p "$dir" test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3" ;; - (*) - set -e - pkgs=$(get "$1") + (*) pkgs=$(get "$1") + if test -z "$pkgs" + then + printf "No handler available for package '%s'\n" "$1" >&2 + exit 2 + fi echo "$pkgs" | while read pkg; do underline "$pkg" name="$(basename $pkg)" diff --git a/instalee.1 b/instalee.1 index 8f1ef73..1d2ad8c 100644 --- a/instalee.1 +++ b/instalee.1 @@ -11,7 +11,7 @@ instalee - Unix-style universal package management wrapper .B instalee .br -.B instalee [-a] [] +.B instalee [-a|--add] [] .SH DESCRIPTION @@ -41,7 +41,7 @@ There is also a special "manager" called "custom". A package file with that name The package to install. Corresponds to a directory in "packages". .TP --a +-a|--add Add a package, instead of installing it. .TP @@ -50,11 +50,23 @@ Name of the packager for which this entry is meant, plus potential pre- and suff Content of the file for the package to be added. If omitted, the file is opened with $EDITOR. Note that the parent directory is definitely created by then, but the file isn't. +.SH EXIT CODES + +.TP +0 +Success +.TP +1 +Unexpected exit +.TP +2 +Could not install all packages + .SH PHILOSOPHY -instalee is meant to closely follow the UNIX philosophy, by using directory structures and files instead of configuration files. The goal is to be as generic as possible, but there are still a few exceptions. If you have an idea how to incorporate them generically, I am all ears. +instalee is meant to closely follow the UNIX philosophy, by using directory structures and files as configuration. The goal is to be as generic as possible, but there are still a few exceptions. If you have an idea how to incorporate them generically, I am all ears. .RS -\(bu THe "custom" package file type, as explained above. +\(bu The "custom" package file type, as explained above. .RE .RS \(bu A manager must not start with a number nor contain any underscores.