all repos — scriptura @ baa93ca20f6525c97091d5ece5861d4526b5591c

a corner in $HOME for your scripts

re-work to use subcommands instead of flags

Alin
commit

baa93ca20f6525c97091d5ece5861d4526b5591c

parent

ad7bee32729173b5eba713b81cd01e2f030d0c36

1 file changed, 51 insertions(+), 60 deletions(-)

changed files
M tests/scriptura.fishtests/scriptura.fish
@@ -27,7 +27,7 @@ set --erase SCRIPTURA_ROOT
set --erase SD_ROOT source $(status dirname)/../functions/scriptura.fish scriptura -) = "\$SCRIPTURA_ROOT $HOME/sd does not exist, use `scriptura --new` to create it" +) = "\$SCRIPTURA_ROOT $HOME/sd does not exist, use `scriptura new` to create it" # Test: SCRIPTURA_ROOT uses SD_ROOT when set @test "SCRIPTURA_ROOT uses SD_ROOT when set" (
@@ -35,7 +35,7 @@ set --erase SCRIPTURA_ROOT
set --global --export SD_ROOT "/custom/sd" source $(status dirname)/../functions/scriptura.fish scriptura -) = "\$SCRIPTURA_ROOT /custom/sd does not exist, use `scriptura --new` to create it" +) = "\$SCRIPTURA_ROOT /custom/sd does not exist, use `scriptura new` to create it" # Test: SCRIPTURA_ROOT uses existing value when set @test "SCRIPTURA_ROOT uses existing value when set" (
@@ -43,7 +43,7 @@ set --global --export SCRIPTURA_ROOT "/existing/root"
set --global --export SD_ROOT "/custom/sd" source $(status dirname)/../functions/scriptura.fish scriptura -) = "\$SCRIPTURA_ROOT /existing/root does not exist, use `scriptura --new` to create it" +) = "\$SCRIPTURA_ROOT /existing/root does not exist, use `scriptura new` to create it" # Test: usage is shown when no arguments provided @test "usage is shown when no arguments provided" -n (
@@ -52,96 +52,87 @@ mkdir -p $test_root
scriptura 2>&1 | string match --regex "Usage:" ) -# Test: error when SCRIPTURA_ROOT doesn't exist and --new not used -@test "error when SCRIPTURA_ROOT doesn't exist and --new not used" -n ( +# Test: error when SCRIPTURA_ROOT doesn't exist and new not used +@test "error when SCRIPTURA_ROOT doesn't exist and new not used" -n ( set --global --export SCRIPTURA_ROOT "/nonexistent/path" scriptura 2>&1 | string match --regex "does not exist" ) -# Test: --new creates SCRIPTURA_ROOT if it doesn't exist -@test "--new creates SCRIPTURA_ROOT if it doesn't exist" ( +# Test: new creates SCRIPTURA_ROOT if it doesn't exist +@test "new creates SCRIPTURA_ROOT if it doesn't exist" ( set --global --export SCRIPTURA_ROOT "$test_root/new_root" - scriptura --new > /dev/null 2>&1 + scriptura new > /dev/null 2>&1 path is --type dir $test_root/new_root ) $status -eq 0 -# Test: --new creates a new script -@test "--new creates a new script" ( +# Test: new creates a new script +@test "new creates a new script" ( set --global --export SCRIPTURA_ROOT $test_root set --global --export SCRIPTURA_EDITOR "touch" - scriptura --new test_script + scriptura new test_script path is --type file --perm exec "$test_root/test_script" ) $status -eq 0 -# Test: --new creates script with shebang -@test "--new creates script with shebang" ( +# Test: new creates script with shebang +@test "new creates script with shebang" ( set --global --export SCRIPTURA_ROOT $test_root set --global --export SCRIPTURA_EDITOR "touch" - scriptura --new shebang_test + scriptura new shebang_test head -n 1 "$test_root/shebang_test" ) = "#!/usr/bin/env fish" -# Test: --new creates component directories -@test "--new creates component directories" ( +# Test: new creates component directories +@test "new creates component directories" ( set --global --export SCRIPTURA_ROOT $test_root set --global --export SCRIPTURA_EDITOR "touch" - scriptura --new foo bar baz + scriptura new foo bar baz path is --type dir "$test_root/foo/bar" path is --type file --perm exec "$test_root/foo/bar/baz" ) $status -eq 0 -# Test: --new fails if script already exists -@test "--new fails if script already exists" -n ( +# Test: new fails if script already exists +@test "new fails if script already exists" -n ( set --global --export SCRIPTURA_ROOT $test_root touch "$test_root/existing_script" - scriptura --new existing_script 2>&1 | string match --regex "already exists" + scriptura new existing_script 2>&1 | string match --regex "already exists" ) -# Test: --new with -- creates script with remaining arguments -@test "--new with -- creates script with remaining arguments" ( +# Test: new with -- creates script with remaining arguments +@test "new with -- creates script with remaining arguments" ( set --global --export SCRIPTURA_ROOT $test_root - scriptura --new new_script -- echo foo + scriptura new new_script -- echo foo path is --type file --perm exec "$test_root/new_script" tail -n 1 "$test_root/new_script" ) = "echo foo" -# Test: --new --edit with -- creates script with remaining arguments -@test "--new --edit with -- creates script with remaining arguments" ( - set --global --export SCRIPTURA_ROOT $test_root - set --global --export SCRIPTURA_EDITOR "sed -i s/foo/bar/" - scriptura --new --edit new_edit_script -- echo foo - path is --type file --perm exec "$test_root/new_edit_script" - tail -n 1 "$test_root/new_edit_script" -) = "echo bar" - -# Test: --which shows path for executable script -@test "--which shows path for executable script" ( +# Test: which shows path for executable script +@test "which shows path for executable script" ( set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\necho test\n" > "$test_root/which_test" chmod +x "$test_root/which_test" - scriptura --which which_test + scriptura which which_test ) = "$test_root/which_test" -# Test: --which fails for non-executable file -@test "--which fails for non-executable file" ( +# Test: which fails for non-executable file +@test "which fails for non-executable file" ( set --global --export SCRIPTURA_ROOT $test_root touch "$test_root/non_exec" - scriptura --which non_exec + scriptura which non_exec ) $status -ne 0 -# Test: --cat displays script content -@test "--cat displays script content" ( +# Test: cat displays script content +@test "cat displays script content" ( set --global --export SCRIPTURA_ROOT $test_root echo "# Test content" > "$test_root/cat_test" - scriptura --cat cat_test + scriptura cat cat_test ) = "# Test content" -# Test: --help shows help for script -@test "--help shows help for script" ( +# Test: help shows help for script +@test "help shows help for script" ( set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\n# This is a test script\necho hello\n" > "$test_root/help_test" chmod +x "$test_root/help_test" - scriptura --help help_test + scriptura help help_test ) = "This is a test script" # Test: script execution works for executable scripts
@@ -149,21 +140,21 @@ @test "script execution works for executable scripts" (
set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\necho 'executed successfully'\n" > "$test_root/exec_test" chmod +x "$test_root/exec_test" - scriptura exec_test + scriptura run exec_test ) = "executed successfully" # Test: non-executable script shows error and content @test "non-executable script shows error and content" -n ( set --global --export SCRIPTURA_ROOT $test_root echo "# Non-executable content" > "$test_root/non_exec_test" - scriptura non_exec_test 2>&1 | string match --regex "not executable" + scriptura run non_exec_test 2>&1 | string match --regex "not executable" ) # Test: directory listing shows directories @test "directory listing shows directories" -n ( set --global --export SCRIPTURA_ROOT $test_root mkdir -p "$test_root/test_dir" - scriptura 2>&1 | string match --regex "test_dir" + scriptura run 2>&1 | string match --regex "^test_dir" ) # Test: directory listing shows executable files
@@ -171,7 +162,7 @@ @test "directory listing shows executable files" -n (
set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\n# Test script\n" > "$test_root/list_test" chmod +x "$test_root/list_test" - scriptura 2>&1 | string match --regex "list_test" + scriptura run 2>&1 | string match --regex "list_test" ) # Test: directory listing with argument shows children
@@ -180,7 +171,7 @@ set --global --export SCRIPTURA_ROOT $test_root
mkdir -p "$test_root/test_dir" printf "#!/usr/bin/env fish\n# Test script\n" > "$test_root/test_dir/test_script" chmod +x "$test_root/test_dir/test_script" - scriptura test_dir 2>&1 | string match "test_script*" + scriptura run test_dir 2>&1 | string match "test_script*" ) # Test: help file is used for directories
@@ -188,7 +179,7 @@ @test "help file is used for directories" (
set --global --export SCRIPTURA_ROOT $test_root mkdir -p "$test_root/help_dir" echo "Directory help text" > "$test_root/help_dir/help" - scriptura --help help_dir + scriptura help help_dir ) = "Directory help text" # Test: .help file is used for scripts
@@ -197,7 +188,7 @@ set --global --export SCRIPTURA_ROOT $test_root
printf "#!/usr/bin/env fish\n" > "$test_root/help_file_test" chmod +x "$test_root/help_file_test" echo "External help text" > "$test_root/help_file_test.help" - scriptura --help help_file_test + scriptura help help_file_test ) = "External help text" # Test: script description extracted from comments
@@ -205,7 +196,7 @@ @test "script description extracted from comments" (
set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\n# This is the description\n# Another comment\n" > "$test_root/desc_test" chmod +x "$test_root/desc_test" - scriptura --help desc_test + scriptura help desc_test ) = "This is the description\nAnother comment" # Test: nested path resolution works
@@ -214,7 +205,7 @@ set --global --export SCRIPTURA_ROOT $test_root
mkdir -p "$test_root/level1/level2" printf "#!/usr/bin/env fish\necho nested\n" > "$test_root/level1/level2/nested_test" chmod +x "$test_root/level1/level2/nested_test" - scriptura level1 level2 nested_test + scriptura run level1 level2 nested_test ) = nested # Test: arguments passed to executed script
@@ -222,7 +213,7 @@ @test "arguments passed to executed script" (
set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\necho \$argv\n" > "$test_root/args_test" chmod +x "$test_root/args_test" - scriptura args_test arg1 arg2 + scriptura run args_test arg1 arg2 ) = "arg1 arg2" # Test: -- stops argument processing
@@ -231,7 +222,7 @@ set --global --export SCRIPTURA_ROOT $test_root
mkdir -p "$test_root/dash_test" printf "#!/usr/bin/env fish\necho dash_dir\n" > "$test_root/dash_test/script" chmod +x "$test_root/dash_test/script" - scriptura dash_test -- script 2>&1 | string match "script*" + scriptura run dash_test -- script 2>&1 | string match "script*" ) # Test: SCRIPTURA_CAT is used when set
@@ -239,7 +230,7 @@ @test "SCRIPTURA_CAT is used when set" "$(
set --global --export SCRIPTURA_ROOT $test_root set --global --export SCRIPTURA_CAT "head -n 1" printf "line1\nline2\nline3" > "$test_root/cat_custom_test" - scriptura --cat cat_custom_test + scriptura cat cat_custom_test )" = line1 # Test: SD_CAT is used as fallback for SCRIPTURA_CAT
@@ -248,20 +239,20 @@ set --global --export SCRIPTURA_ROOT $test_root
set --erase SCRIPTURA_CAT set --global --export SD_CAT "head -n 1" printf "line1\nline2\nline3" > "$test_root/sd_cat_test" - scriptura --cat sd_cat_test + scriptura cat sd_cat_test ) = line1 # Test: unknown target shows error @test "unknown target shows error" "$( set --global --export SCRIPTURA_ROOT $test_root - scriptura nonexistent_target 2>&1 + scriptura run nonexistent_target 2>&1 )" = 'scriptura: don\'t know what to do with target "nonexistent_target"' # Test: help for directory without help file shows default @test "help for directory without help file shows default" ( set --global --export SCRIPTURA_ROOT $test_root mkdir -p "$test_root/no_help_dir" - scriptura --help no_help_dir + scriptura help no_help_dir ) = "no_help_dir commands" # Test: shebang lines are excluded from description
@@ -269,7 +260,7 @@ @test "shebang lines are excluded from description" (
set --global --export SCRIPTURA_ROOT $test_root printf "#!/usr/bin/env fish\n#! Not a shebang\n# Real description\n" > "$test_root/shebang_desc_test" chmod +x "$test_root/shebang_desc_test" - scriptura --help shebang_desc_test + scriptura help shebang_desc_test ) = "Real description" # Cleanup