diff options
| author | EuAndreh <eu@euandre.org> | 2026-06-12 10:59:00 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-06-12 10:59:00 -0300 |
| commit | b9f2ad6b22fe6808a5cd2a1476172a1131adb3ed (patch) | |
| tree | 56b7153976edf43fe92b17917209e9a4fadd2112 | |
| parent | Rewrite remembering in Go (diff) | |
| download | remembering-b9f2ad6b22fe6808a5cd2a1476172a1131adb3ed.tar.gz remembering-b9f2ad6b22fe6808a5cd2a1476172a1131adb3ed.tar.xz | |
Accept getopts-style attached -pPROFILE again
Via gobang.ExpandBundles("p:", argv), now that it understands
optstring value flags: -pp1 expands to -p p1 before stdlib flag
parsing, and nothing after "--" is expanded, so the wrapped
command's own argv passes through byte-for-byte.
signals.sh goes back to its original attached-form invocations,
which now double as the compat test.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
| -rw-r--r-- | doc/remembering.en.1.adoc | 3 | ||||
| -rw-r--r-- | src/remembering.go | 5 | ||||
| -rw-r--r-- | tests/remembering.go | 23 | ||||
| -rwxr-xr-x | tests/signals.sh | 8 |
4 files changed, 33 insertions, 6 deletions
diff --git a/doc/remembering.en.1.adoc b/doc/remembering.en.1.adoc index 9d5f859..568f86a 100644 --- a/doc/remembering.en.1.adoc +++ b/doc/remembering.en.1.adoc @@ -75,7 +75,8 @@ nothing, and exits 0. *-p* _PROFILE_:: The profile name to gather and store the ranking under (default: -the current directory, with every `/` turned into `!`). +the current directory, with every `/` turned into `!`). The +attached getopts form (`-pPROFILE`) is accepted too. diff --git a/src/remembering.go b/src/remembering.go index 8d2a017..f802ffc 100644 --- a/src/remembering.go +++ b/src/remembering.go @@ -14,6 +14,8 @@ import ( "strconv" "strings" "syscall" + + "gobang" ) @@ -250,7 +252,8 @@ func run(env envT) int { flags.SetOutput(env.err) profileName := flags.String("p", "", "") - if flags.Parse(env.allArgs[1:]) != nil { + argv := gobang.ExpandBundles("p:", env.allArgs[1:]) + if flags.Parse(argv) != nil { usage(env.err) return 2 } diff --git a/tests/remembering.go b/tests/remembering.go index 3f8e446..5c3b705 100644 --- a/tests/remembering.go +++ b/tests/remembering.go @@ -505,6 +505,29 @@ func test_run_flow() { assertEq(out, "x\n") assertEq(errW, "warn\n") }) + + testing("attached -pNAME is accepted", func() { + rc, out, _ := runWith( + "b\na\n", + "-pt8", "--", "head", "-n1", + ) + assertEq(rc, 0) + assertEq(out, "a\n") + assertEq( + profileContent("t8"), + "1 profile a\n0 profile b\n", + ) + }) + + testing("-- shields the command's argv", func() { + rc, out, _ := runWith( + "", + "-p", "t9", "--", + "sh", "-c", "echo \"$0\"", "-pz", + ) + assertEq(rc, 0) + assertEq(out, "-pz\n") + }) }) } diff --git a/tests/signals.sh b/tests/signals.sh index e1cb063..368a096 100755 --- a/tests/signals.sh +++ b/tests/signals.sh @@ -12,15 +12,15 @@ test_status_is_zero_when_command_is_successful() { testing 'status is 0 when command is successful' N="$LINENO" - printf 'a\n' | "$REMEMBERING" -p p1 -- head -n1 1>/dev/null 2>/dev/null + printf 'a\n' | "$REMEMBERING" -pp1 -- head -n1 1>/dev/null 2>/dev/null STATUS=$? assert_status 0 - printf '' | "$REMEMBERING" -p p2 -- true 1>/dev/null 2>/dev/null + printf '' | "$REMEMBERING" -pp2 -- true 1>/dev/null 2>/dev/null STATUS=$? assert_status 0 - seq 9 | "$REMEMBERING" -p p3 -- grep 7 1>/dev/null 2>/dev/null + seq 9 | "$REMEMBERING" -pp3 -- grep 7 1>/dev/null 2>/dev/null STATUS=$? assert_status 0 @@ -31,7 +31,7 @@ test_status_is_forwarded_from_command() { testing 'status is forwarded from command' N="$LINENO" for status in $(seq 1 125); do - printf '' | "$REMEMBERING" -p p4 -- sh -c "exit $status" 1>/dev/null 2>/dev/null + printf '' | "$REMEMBERING" -pp4 -- sh -c "exit $status" 1>/dev/null 2>/dev/null STATUS=$? assert_status "$status" done |
