fix(cli): prevent typos from being treated as URLs
Remove URL argument handling from root command to properly catch command typos. Previously 'dumber pruge' would search Google for 'pruge' instead of showing 'unknown command' error. Users must now use 'dumber browse <url>' explicitly.
- commit
- 00eb4e3b003de33a7805bcde328cf2233145302f
- author
- bnema · · 2025-10-24 04:43 UTC
- committer
- bnema · · 2025-10-24 17:33 UTC
- parent
- 6b6efd7
- signature
- GPG Unverified
2B82207D370127A0The key is unknown
1 file · +3 -20
M internal/cli/root.go +3 -20
| @@ -95,28 +95,11 @@ func (c *CLI) Close() error { | |||
| 95 | 95 | // NewRootCmd creates the root command for dumber | |
| 96 | 96 | func NewRootCmd(version, commit, buildDate string) *cobra.Command { | |
| 97 | 97 | rootCmd := &cobra.Command{ | |
| 98 | - | Use: "dumber [url]", | |
| 98 | + | Use: "dumber", | |
| 99 | 99 | Short: "A dumb browser for Wayland window managers", | |
| 100 | 100 | Long: `A fast, simple browser with rofi/dmenu integration for sway and hyprland window managers.`, | |
| 101 | - | Args: cobra.MaximumNArgs(1), | |
| 102 | - | RunE: func(cmd *cobra.Command, args []string) error { | |
| 103 | - | // Initialize CLI | |
| 104 | - | cli, err := NewCLI() | |
| 105 | - | if err != nil { | |
| 106 | - | return fmt.Errorf("failed to initialize CLI: %w", err) | |
| 107 | - | } | |
| 108 | - | defer func() { | |
| 109 | - | if closeErr := cli.Close(); closeErr != nil { | |
| 110 | - | fmt.Fprintf(os.Stderr, "Warning: failed to close database: %v\n", closeErr) | |
| 111 | - | } | |
| 112 | - | }() | |
| 113 | - | ||
| 114 | - | // If URL provided, browse it directly | |
| 115 | - | if len(args) > 0 { | |
| 116 | - | return browse(cli, args[0]) | |
| 117 | - | } | |
| 118 | - | ||
| 119 | - | // Otherwise show help | |
| 101 | + | RunE: func(cmd *cobra.Command, _ []string) error { | |
| 102 | + | // Show help when no subcommand is provided | |
| 120 | 103 | return cmd.Help() | |
| 121 | 104 | }, | |
| 122 | 105 | } | |
| @@ -95,28 +95,11 @@ func (c *CLI) Close() error { | |||||
| 95 | // NewRootCmd creates the root command for dumber | 95 | // NewRootCmd creates the root command for dumber | ||
| 96 | func NewRootCmd(version, commit, buildDate string) *cobra.Command { | 96 | func NewRootCmd(version, commit, buildDate string) *cobra.Command { | ||
| 97 | rootCmd := &cobra.Command{ | 97 | rootCmd := &cobra.Command{ | ||
| 98 | - | Use: "dumber [url]", | 98 | + | Use: "dumber", |
| 99 | Short: "A dumb browser for Wayland window managers", | 99 | Short: "A dumb browser for Wayland window managers", | ||
| 100 | Long: `A fast, simple browser with rofi/dmenu integration for sway and hyprland window managers.`, | 100 | Long: `A fast, simple browser with rofi/dmenu integration for sway and hyprland window managers.`, | ||
| 101 | - | Args: cobra.MaximumNArgs(1), | 101 | + | RunE: func(cmd *cobra.Command, _ []string) error { |
| 102 | - | RunE: func(cmd *cobra.Command, args []string) error { | 102 | + | // Show help when no subcommand is provided |
| 103 | - | // Initialize CLI | |||
| 104 | - | cli, err := NewCLI() | |||
| 105 | - | if err != nil { | |||
| 106 | - | return fmt.Errorf("failed to initialize CLI: %w", err) | |||
| 107 | - | } | |||
| 108 | - | defer func() { | |||
| 109 | - | if closeErr := cli.Close(); closeErr != nil { | |||
| 110 | - | fmt.Fprintf(os.Stderr, "Warning: failed to close database: %v\n", closeErr) | |||
| 111 | - | } | |||
| 112 | - | }() | |||
| 113 | - | ||||
| 114 | - | // If URL provided, browse it directly | |||
| 115 | - | if len(args) > 0 { | |||
| 116 | - | return browse(cli, args[0]) | |||
| 117 | - | } | |||
| 118 | - | ||||
| 119 | - | // Otherwise show help | |||
| 120 | return cmd.Help() | 103 | return cmd.Help() | ||
| 121 | }, | 104 | }, | ||
| 122 | } | 105 | } | ||