From 98499e7226a7f9859d6de332b5797ae9b133a168 Mon Sep 17 00:00:00 2001 From: Narrator Date: Thu, 29 Oct 2026 19:18:52 +0100 Subject: [PATCH] Check -layout and -theme before -reset moves anything aside 'interzone -reset -layout bogus' moved the config and data folders away and only then complained about the layout. Options are now checked first. 'interzone -plain check' says the command goes first instead of calling it unknown, and 'interzone help' prints the options as -h does. Co-Authored-By: Claude Opus 5.5 --- main.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index ca1387a..df182fd 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "os" + "slices" "strings" tea "github.com/charmbracelet/bubbletea" @@ -23,10 +24,6 @@ var version = "dev" func main() { deploy.Version = version if len(os.Args) > 1 { - if os.Args[1] == "help" { - fmt.Println(cli.Usage) - return - } if cmd, ok := cli.Commands[os.Args[1]]; ok { if err := cmd(os.Args[2:]); err != nil { var pe *fs.PathError @@ -51,12 +48,30 @@ func main() { fmt.Fprintln(flag.CommandLine.Output(), cli.Usage+"\n\nOptions:") flag.PrintDefaults() } + if len(os.Args) > 1 && os.Args[1] == "help" { + flag.CommandLine.SetOutput(os.Stdout) + flag.Usage() + return + } flag.Parse() if flag.NArg() > 0 { + if _, ok := cli.Commands[flag.Arg(0)]; ok { + fmt.Fprintf(os.Stderr, "interzone: %q is a command; put it first, with its own options after it\n", flag.Arg(0)) + os.Exit(2) + } fmt.Fprintf(os.Stderr, "interzone: unknown command %q\n\n", flag.Arg(0)) flag.Usage() os.Exit(2) } + // Check the options before -reset moves anything aside. + if *layout != "" && *layout != "auto" && *layout != "compact" && *layout != "wide" { + fmt.Fprintf(os.Stderr, "interzone: -layout is auto, compact or wide, not %q\n", *layout) + os.Exit(2) + } + if *theme != "" && !slices.Contains(ui.ThemeNames(), *theme) { + fmt.Fprintf(os.Stderr, "interzone: -theme is one of %s, not %q\n", strings.Join(ui.ThemeNames(), ", "), *theme) + os.Exit(2) + } if *showVersion { fmt.Println("interzone", version) @@ -84,15 +99,10 @@ func main() { } app := ui.New(cfg, loaded) if *layout != "" { - if *layout != "auto" && *layout != "compact" && *layout != "wide" { - fmt.Fprintf(os.Stderr, "interzone: -layout is auto, compact or wide, not %q\n", *layout) - os.Exit(2) - } app.SetLayout(*layout) } - if *theme != "" && !ui.SetTheme(*theme) { - fmt.Fprintf(os.Stderr, "interzone: -theme is one of %s, not %q\n", strings.Join(ui.ThemeNames(), ", "), *theme) - os.Exit(2) + if *theme != "" { + ui.SetTheme(*theme) } p := tea.NewProgram(app, opts...) if _, err := p.Run(); err != nil {