aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanix <danix@danix.xyz>2026-06-11 10:10:16 +0200
committerdanix <danix@danix.xyz>2026-06-11 10:10:16 +0200
commit2f6f5e0920efd60150bbd7c93cefce7281d68c78 (patch)
tree2a1b65dbdcd838847eb9480290feb6d989fe38ab
parent17920afbe5ab2c1ba3e81c9a38a0c924ccd9d1a0 (diff)
downloadwallp-2f6f5e0920efd60150bbd7c93cefce7281d68c78.tar.gz
wallp-2f6f5e0920efd60150bbd7c93cefce7281d68c78.zip
feat: help screen + main dispatch
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rw-r--r--tests/wallp.bats30
-rw-r--r--wallp46
2 files changed, 75 insertions, 1 deletions
diff --git a/tests/wallp.bats b/tests/wallp.bats
index ad4b9bf..0d6fc7e 100644
--- a/tests/wallp.bats
+++ b/tests/wallp.bats
@@ -237,3 +237,33 @@ teardown() {
[ "$status" -eq 1 ]
[[ "$output" == *"no display"* ]]
}
+
+@test "bare invocation shows help" {
+ unset WAYLAND_DISPLAY
+ run main
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"Usage"* ]]
+}
+
+@test "unknown flag errors with help" {
+ unset WAYLAND_DISPLAY
+ run main --bogus
+ [ "$status" -eq 1 ]
+ [[ "$output" == *"Usage"* ]]
+}
+
+@test "bootstrap on missing conf exits zero without setting wallpaper" {
+ unset WAYLAND_DISPLAY
+ run main --restore
+ [ "$status" -eq 0 ]
+ [ ! -e "$HOME/.cache/wallp/H.pid" ]
+}
+
+@test "theme flag honored through main with restore" {
+ unset WAYLAND_DISPLAY
+ mkdir -p "$HOME/.config/wallp"
+ printf '%s\n' 'OUTPUT_H=DP-1' 'OUTPUT_V=DP-3' \
+ 'DEFAULT_H=/dh.png' 'DEFAULT_V=/dv.png' > "$HOME/.config/wallp/wallp.conf"
+ main --restore --theme tflag
+ [ "$(cat "$HOME/.config/wallp/theme")" = "tflag" ]
+}
diff --git a/wallp b/wallp
index 11bcf80..d021c2b 100644
--- a/wallp
+++ b/wallp
@@ -241,8 +241,52 @@ do_set() {
finalize "$(resolve_theme "$flag_theme")"
}
+show_help() {
+ local text="wallp — unified wallpaper manager
+
+Usage:
+ wallp Show this help
+ wallp --help | -h Show this help
+ wallp --set Interactive (qarma) wallpaper selection
+ wallp --set H=<file> Set horizontal screen only
+ wallp --set V=<file> Set vertical screen only
+ wallp --set H=<f> V=<f> Set both screens
+ wallp --restore Restore last session (defaults if none)
+ wallp --theme <name> Override theme (with --set or --restore)
+
+Config: ~/.config/wallp/wallp.conf"
+ if [ -n "${WAYLAND_DISPLAY:-}" ] && command -v qarma >/dev/null 2>&1; then
+ qarma --info --title="wallp help" --text="$text" 2>/dev/null
+ else
+ printf '%s\n' "$text"
+ fi
+}
+
main() {
- return 0
+ local action="" flag_theme="" set_args=()
+ while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --help|-h) show_help; return 0 ;;
+ --set) action="set" ;;
+ --restore) action="restore" ;;
+ --theme) shift; flag_theme="${1:-}";
+ [ -z "$flag_theme" ] && { echo "wallp: --theme needs a name" >&2; return 1; } ;;
+ H=*|V=*) set_args+=("$1") ;;
+ *) echo "wallp: unknown argument '$1'" >&2; show_help; return 1 ;;
+ esac
+ shift
+ done
+
+ if [ -z "$action" ]; then show_help; return 0; fi
+
+ load_conf; local rc=$?
+ if [ "$rc" -eq 10 ]; then return 0; fi # bootstrapped, no change
+ if [ "$rc" -ne 0 ]; then return 1; fi
+
+ case "$action" in
+ set) do_set "$flag_theme" "${set_args[@]}" ;;
+ restore) do_restore "$flag_theme" ;;
+ esac
}
if [ "${BASH_SOURCE[0]}" = "$0" ]; then main "$@"; fi