Skip to content

feat(cli): compact single-dash flag model#21

Merged
root-Manas merged 1 commit intomainfrom
pr/12-compact-flags
Mar 29, 2026
Merged

feat(cli): compact single-dash flag model#21
root-Manas merged 1 commit intomainfrom
pr/12-compact-flags

Conversation

@root-Manas
Copy link
Copy Markdown
Owner

Implements compact 3-4 letter flags (e.g. -scn, -sts, -srv), adds normalization for legacy/long flags, and updates parser tests.

Copilot AI review requested due to automatic review settings March 29, 2026 06:31
@root-Manas root-Manas merged commit 6c72884 into main Mar 29, 2026
5 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a compact single-dash (3–4 letter) flag model to the macaron CLI, along with argument normalization so older/longer flag forms can be rewritten into the new compact canonical flags.

Changes:

  • Renames CLI flags to compact 3–4 letter forms (e.g. scn, thr, stp) and updates help/guide text accordingly.
  • Introduces normalizeCompactFlags() to rewrite -xyz and --long flags into the compact canonical --xyz form before parsing.
  • Updates CLI parser tests to cover new normalization behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/macaron/main.go Switches flag registration to compact names, updates help/guide output, and adds compact/legacy flag normalization.
cmd/macaron/main_test.go Updates/extends normalization tests for the new compact flag model.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to +61
func TestNormalizeCommandScan(t *testing.T) {
withArgs([]string{"macaron", "scan", "example.com", "--fast"}, func() {
normalizeCompactFlags()
normalizeCommandArgs()
args := osArgs()
want := []string{"macaron", "--scan", "example.com", "--fast"}
want := []string{"macaron", "--scn", "example.com", "--fst"}
if len(args) != len(want) {
t.Fatalf("unexpected len: %#v", args)
}
for i := range want {
if args[i] != want[i] {
t.Fatalf("idx %d: got %q want %q", i, args[i], want[i])
}
}
})
}

func TestNormalizeLongToCompact(t *testing.T) {
withArgs([]string{"macaron", "--scan", "example.com", "--threads", "20"}, func() {
normalizeCompactFlags()
args := osArgs()
want := []string{"macaron", "--scn", "example.com", "--thr", "20"}
if len(args) != len(want) {
t.Fatalf("unexpected len: %#v", args)
}
for i := range want {
if args[i] != want[i] {
t.Fatalf("idx %d: got %q want %q", i, args[i], want[i])
}
}
})
}

func TestNormalizeSingleDashCompact(t *testing.T) {
withArgs([]string{"macaron", "-stp", "-ver"}, func() {
normalizeCompactFlags()
args := osArgs()
want := []string{"macaron", "--stp", "--ver"}
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization tests cover long flags (--scan, --threads) and 3-letter single-dash flags (-stp, -ver), but they don’t cover the legacy single-letter forms that flagMap claims to support (e.g. -s, -d, -m, -f, -q, -o). Adding at least one test for a 1-letter legacy flag would prevent regressions where shorthands stop being accepted.

Copilot uses AI. Check for mistakes.
args := make([]string, 0, len(os.Args))
args = append(args, os.Args[0])
for _, arg := range os.Args[1:] {
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 {
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizeCompactFlags does not normalize legacy single-letter flags (e.g. -s, -d, -m, -f, -q) because the single-dash branch only runs when len(arg) > 2. This will break previously supported pflag shorthands after removing *VarP declarations, and it also prevents use of the legacy keys already present in flagMap ("s", "d", "m", etc.). Adjust the condition to include 2-char args (and keep the map lookup to avoid changing unrelated - prefixed args).

Suggested change
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 {
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) >= 2 {

Copilot uses AI. Check for mistakes.
Comment on lines 306 to 313
func normalizeLegacyArgs() {
for i, arg := range os.Args {
if arg == "-setup" {
os.Args[i] = "--setup"
os.Args[i] = "-stp"
}
if arg == "-install-tools" {
os.Args[i] = "--install-tools"
os.Args[i] = "-ins"
}
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizeLegacyArgs rewrites -setup/-install-tools to -stp/-ins (single-dash), which still requires a later normalizeCompactFlags pass to become parseable by pflag (otherwise -stp is treated as a shorthand cluster). Consider rewriting legacy args directly to the canonical long form (--stp / --ins) so parsing does not depend on normalization order or future refactors.

Copilot uses AI. Check for mistakes.
root-Manas added a commit that referenced this pull request Mar 29, 2026
This reverts commit 6c72884, reversing
changes made to 51f4d42.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants