fix: document exit codes and flags

This commit is contained in:
xeruf 2022-07-04 13:51:24 +02:00
parent d00b178f1c
commit 61dd6f1a76
2 changed files with 31 additions and 15 deletions

26
instalee Normal file → Executable file
View file

@ -1,6 +1,7 @@
#!/bin/sh #!/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"; } underline() { echo "$1"; }
@ -9,27 +10,30 @@ getcontent() { test -x "$1" && "$1" || cat "$1"; }
# Get available package entries for given package # Get available package entries for given package
get() { 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 do find "$home/packages/$1" -name "$handler*" 2>/dev/null
done)" done
test ! "$result" && echo "No handler for package '$1'" >>/dev/stderr && exit 1
echo "$result"
} }
case "$1" in case "$1" in
(--version) (--version|"")
printf "instalee r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" 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 # 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) (-a|--add)
dir="$home/packages/$2" dir="$home/packages/$2"
mkdir -p "$dir" mkdir -p "$dir"
test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3" test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3"
;; ;;
(*) (*) pkgs=$(get "$1")
set -e if test -z "$pkgs"
pkgs=$(get "$1") then
printf "No handler available for package '%s'\n" "$1" >&2
exit 2
fi
echo "$pkgs" | while read pkg; do echo "$pkgs" | while read pkg; do
underline "$pkg" underline "$pkg"
name="$(basename $pkg)" name="$(basename $pkg)"

View file

@ -11,7 +11,7 @@ instalee - Unix-style universal package management wrapper
.B instalee <packagename> .B instalee <packagename>
.br .br
.B instalee [-a] <packagename> <identifier> [<content>] .B instalee [-a|--add] <packagename> <identifier> [<content>]
.SH DESCRIPTION .SH DESCRIPTION
@ -41,7 +41,7 @@ There is also a special "manager" called "custom". A package file with that name
<packagename> <packagename>
The package to install. Corresponds to a directory in "packages". The package to install. Corresponds to a directory in "packages".
.TP .TP
-a -a|--add
Add a package, instead of installing it. Add a package, instead of installing it.
.TP .TP
<identifier> <identifier>
@ -50,11 +50,23 @@ Name of the packager for which this entry is meant, plus potential pre- and suff
<content> <content>
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. 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 .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 .RS
\(bu THe "custom" package file type, as explained above. \(bu The "custom" package file type, as explained above.
.RE .RE
.RS .RS
\(bu A manager must not start with a number nor contain any underscores. \(bu A manager must not start with a number nor contain any underscores.