commit ec4d031b940089ad3caabc9056d1eb4ca063200d
parent 4bb977a73730be53dacbce4109211bff5776a2a5
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Wed, 29 Oct 2025 20:10:49 +0000
Raw list output has a dedicated action function
Diffstat:
2 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/spec/action_spec.sh b/spec/action_spec.sh
@@ -1,5 +1,5 @@
# pashage - age-backed POSIX password manager
-# Copyright (C) 2024 Natasha Kerensikova
+# Copyright (C) 2024-2025 Natasha Kerensikova
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -1774,6 +1774,15 @@ Describe 'Action Functions'
End
End
+ Describe 'do_list'
+ It 'is not implemented yet'
+ When call do_list "${PREFIX}" 'Base/'
+ The status should be success
+ The output should be blank
+ The error should equal 'TODO: not implemented yet'
+ End
+ End
+
Describe 'do_list_or_show'
PREFIX="${SHELLSPEC_WORKDIR}/prefix"
@@ -1787,6 +1796,8 @@ Describe 'Action Functions'
%putsn data
}
+ do_list() { mocklog do_list "$@"; }
+
do_show() {
@cat >/dev/null
mocklog do_show "$@"
@@ -1809,7 +1820,16 @@ Describe 'Action Functions'
BeforeEach setup
AfterEach cleanup
- It 'lists the whole store'
+ It 'lists the whole store as a list'
+ LIST_VIEW=yes
+ When call do_list_or_show ''
+ The status should be success
+ The output should be blank
+ The error should equal "$ do_list ${PREFIX} "
+ End
+
+ It 'lists the whole store as a tree'
+ LIST_VIEW=no
When call do_list_or_show ''
The status should be success
The output should be blank
@@ -1838,7 +1858,16 @@ Describe 'Action Functions'
The error should equal "$(result)"
End
- It 'lists a subdirectory'
+ It 'lists a subdirectory as a list'
+ LIST_VIEW=yes
+ When call do_list_or_show 'subdir'
+ The status should be success
+ The output should be blank
+ The error should equal "$ do_list ${PREFIX}/subdir subdir/"
+ End
+
+ It 'lists a subdirectory as a tree'
+ LIST_VIEW=no
When call do_list_or_show 'subdir'
The status should be success
The output should be blank
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -847,12 +847,24 @@ do_insert() {
scm_commit "Add given password for $1 to store."
}
+# Display the entry list rooted at the given relative directory
+# $1: root directory
+# $2: path prefix
+# ...: (optional) grep arguments to filter
+do_list() {
+ echo "TODO: not implemented yet" >&2
+}
+
# Display a single directory or entry
# $1: entry name
+# LIST_VIEW: whether directories are displayed as a list rather then a tree
do_list_or_show() {
- : TODO use "${LIST_VIEW-}"
if [ -z "$1" ]; then
- do_tree "${PREFIX}" "Password Store"
+ if [ "${LIST_VIEW-no}" = "yes" ]; then
+ do_list "${PREFIX}" ""
+ else
+ do_tree "${PREFIX}" "Password Store"
+ fi
elif [ -f "${PREFIX}/$1.age" ]; then
SECRET="$(do_decrypt "${PREFIX}/$1.age")"
do_show "$1" <<-EOF
@@ -860,7 +872,11 @@ do_list_or_show() {
EOF
unset SECRET
elif [ -d "${PREFIX}/$1" ]; then
- do_tree "${PREFIX}/$1" "$1"
+ if [ "${LIST_VIEW-no}" = "yes" ]; then
+ do_list "${PREFIX}/$1" "${1%/}/"
+ else
+ do_tree "${PREFIX}/$1" "$1"
+ fi
elif [ -f "${PREFIX}/$1.gpg" ]; then
SECRET="$(do_decrypt_gpg "${PREFIX}/$1.gpg")"
do_show "$1" <<-EOF