From 38914001258d86e229202bef8a393e257ddc9758 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Fri, 28 Nov 2025 09:23:29 +0800 Subject: refactor: use subcommands and replace certain flags --- main.go | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file 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 + }, + }, }, } -- cgit v1.2.3