- add pubcli compare command to rank nearby stores by filtered deal coverage, bogo count, aggregate score, and distance tie-breaks - support --count (1-10) for comparison breadth and emit structured JSON/text output with ranked entries - add robust distance token parsing to tolerate upstream distance string formatting differences - add pubcli tui interactive terminal browser with paging, deal detail drill-in, and explicit TTY validation for stdin/stdout - share deal-filter flag registration across root/tui/compare and add --sort support in root execution path - validate sort mode early and allow canonical aliases (end, expiry, expiration) while preserving explicit invalid-arg guidance - expand tolerant CLI normalization for new commands/flags and aliases (orderby, sortby, count, bare-flag rewrite for compare/tui) - update quick-start flag list and integration tests to cover compare help and normalization behavior
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNormalizeCLIArgs_RewritesCommonFlagSyntax(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"-zip", "33101", "json"})
|
|
|
|
assert.Equal(t, []string{"--zip", "33101", "--json"}, args)
|
|
assert.NotEmpty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_RewritesTypoFlag(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"--ziip", "33101"})
|
|
|
|
assert.Equal(t, []string{"--zip", "33101"}, args)
|
|
assert.NotEmpty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_RewritesSortAlias(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"orderby=savings"})
|
|
|
|
assert.Equal(t, []string{"--sort=savings"}, args)
|
|
assert.NotEmpty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_RewritesCommandTypo(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"categoriess", "--zip", "33101"})
|
|
|
|
assert.Equal(t, []string{"categories", "--zip", "33101"}, args)
|
|
assert.NotEmpty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_DoesNotRewriteCompletionPositionalArgs(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"completion", "zsh"})
|
|
|
|
assert.Equal(t, []string{"completion", "zsh"}, args)
|
|
assert.Empty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_DoesNotRewriteHelpCommandArgAsFlag(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"help", "stores"})
|
|
|
|
assert.Equal(t, []string{"help", "stores"}, args)
|
|
assert.Empty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_RespectsDoubleDashBoundary(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"stores", "--", "zip", "33101"})
|
|
|
|
assert.Equal(t, []string{"stores", "--", "zip", "33101"}, args)
|
|
assert.Empty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_RewritesBareFlagsForCompare(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"compare", "zip", "33101"})
|
|
|
|
assert.Equal(t, []string{"compare", "--zip", "33101"}, args)
|
|
assert.NotEmpty(t, notes)
|
|
}
|
|
|
|
func TestNormalizeCLIArgs_LeavesKnownShorthandUntouched(t *testing.T) {
|
|
args, notes := normalizeCLIArgs([]string{"-z", "33101", "-n", "5"})
|
|
|
|
assert.Equal(t, []string{"-z", "33101", "-n", "5"}, args)
|
|
assert.Empty(t, notes)
|
|
}
|
|
|
|
func TestExplainCLIError_UnknownFlagIncludesSuggestionAndExamples(t *testing.T) {
|
|
msg := explainCLIError(errors.New("unknown flag: --ziip"))
|
|
|
|
assert.Contains(t, msg, "Try `--zip`.")
|
|
assert.Contains(t, msg, "pubcli --zip 33101")
|
|
assert.Contains(t, msg, "pubcli --store 1425 --bogo")
|
|
}
|
|
|
|
func TestExplainCLIError_UnknownCommandIncludesSuggestionAndExamples(t *testing.T) {
|
|
msg := explainCLIError(errors.New("unknown command \"stors\" for \"pubcli\""))
|
|
|
|
assert.Contains(t, msg, "Did you mean `stores`?")
|
|
assert.Contains(t, msg, "pubcli stores --zip 33101")
|
|
assert.Contains(t, msg, "pubcli categories --zip 33101")
|
|
}
|