summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-28 09:23:29 +0800
committerEltrac <hi@guhub.cn>2025-11-28 09:23:29 +0800
commit38914001258d86e229202bef8a393e257ddc9758 (patch)
treedfc7b8da3089a59047a118f4c14e08106276e360
parentf8549409b83c5a7d405d4dfb4902b9598698fd23 (diff)
refactor: use subcommands and replace certain flags
-rw-r--r--main.go56
1 files changed, 36 insertions, 20 deletions
diff --git a/main.go b/main.go
index 5d1bda6..8ec0015 100644
--- a/main.go
+++ b/main.go
@@ -26,30 +26,46 @@ func main() {
Value: false,
Destination: &NoCache,
},
- &cli.BoolFlag{
- Name: "clear-cache",
- Aliases: []string{"cc"},
- Usage: "Clear cache",
- Value: false,
- Destination: &DoClearCache,
- },
},
- Action: func(ctx context.Context, cmd *cli.Command) error {
- if DoClearCache {
- ClearCache()
- fmt.Println("Cache cleared.")
- os.Exit(0)
- }
+ // Action: func(ctx context.Context, cmd *cli.Command) error {
- // check args
- if cmd.Args().Len() == 0 {
- printErrorAndExit("Please provide a formulae/cask name.")
- }
- // do the job
- searchAndPrint(cmd.Args().First())
+ // return nil
+ // },
+ Commands: []*cli.Command{
+ {
+ Name: "info",
+ Aliases: []string{"i"},
+ Usage: "Show info and reverse dependencies of a formula/cask.",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ if cmd.Args().Len() == 0 {
+ printErrorAndExit("Please provide a formulae/cask name.")
+ }
+ searchAndPrint(cmd.Args().First())
- return nil
+ return nil
+ },
+ },
+ {
+ Name: "list",
+ Aliases: []string{"l", "ls"},
+ Usage: "Better brew list.",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ // TODO
+ return nil
+ },
+ },
+ {
+ Name: "clean",
+ Aliases: []string{"c", "cache"},
+ Usage: "Delete all cache files.",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ // TODO error handling here
+ ClearCache()
+ fmt.Println("Cache cleared.")
+ return nil
+ },
+ },
},
}