Files
NarratorandClaude Opus 5.5 3b0292d644 Commands take their options after the arguments too
Go's flag package stops at the first argument, so 'restore dump.sql
--yes' still asked (and failed silently under cron), 'rollback 3
--quiet' wasn't quiet and 'import PATH --dry-run' printed the usage.
Every command now parses with a helper that keeps reading options after
the arguments; "--" still ends them. restore and rollback reject extra
arguments, 'servers rm' without a name prints the usage, and Usage
mentions 'servers rm'.

Rollback also exits 1 when the self-check after it finds problems, the
way apply does, and keeps the answers it replaces in
<server>.json.before-rollback: config.before-rollback.json was shared by
every server, so rolling back one overwrote another's copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 19:18:52 +01:00

31 lines
826 B
Go

package cli
import (
"flag"
"slices"
"testing"
)
func TestParseInterspersed(t *testing.T) {
for _, tc := range []struct {
args []string
yes bool
pos []string
}{
{[]string{"--yes", "dump.sql"}, true, []string{"dump.sql"}},
{[]string{"dump.sql", "--yes"}, true, []string{"dump.sql"}},
{[]string{"a", "-yes", "b"}, true, []string{"a", "b"}},
{[]string{"dump.sql"}, false, []string{"dump.sql"}},
{[]string{"--", "-yes"}, false, []string{"-yes"}},
{[]string{"a", "--", "-yes"}, false, []string{"a", "-yes"}},
{nil, false, nil},
} {
fs := flag.NewFlagSet("t", flag.ContinueOnError)
yes := fs.Bool("yes", false, "")
parse(fs, tc.args)
if *yes != tc.yes || !slices.Equal(fs.Args(), tc.pos) {
t.Errorf("parse(%q): yes=%v args=%q, want %v %q", tc.args, *yes, fs.Args(), tc.yes, tc.pos)
}
}
}