update-go-mod/internal/cli/app.go

102 lines
1.8 KiB
Go
Raw Normal View History

2022-07-22 14:09:34 +00:00
package cli
import (
"os"
2024-03-01 07:18:54 +00:00
"github.com/google/go-github/v60/github"
2022-07-22 14:09:34 +00:00
"github.com/urfave/cli/v2"
2023-02-25 16:14:43 +00:00
"github.com/make-go-great/color-go"
2022-07-22 14:09:34 +00:00
)
const (
name = "update-go-mod"
usage = "excatly like the name says"
2022-08-16 03:34:55 +00:00
commandRunName = "run"
commandRunUsage = "run the program"
2022-07-22 14:09:34 +00:00
2023-08-15 10:59:16 +00:00
commandOverlookName = "overlook"
commandOverlookUsage = "take a quick lock"
2022-08-16 03:34:55 +00:00
flagVerboseName = "verbose"
flagVerboseUsage = "show what is going on"
2022-07-22 14:09:34 +00:00
2022-08-16 03:34:55 +00:00
flagDepsFileName = "deps-file"
flagDepsFileUsage = "file which show what deps need to upgrade"
2022-07-22 15:50:51 +00:00
2022-08-16 03:34:55 +00:00
flagDepsURLName = "deps-url"
flagDepsURLUsage = "url which show what deps need to upgrade"
flagDryRun = "dry-run"
flagDryRunName = "demo what would be done"
2022-07-22 14:09:34 +00:00
)
var aliasFlagVerbose = []string{"v"}
type App struct {
2023-08-15 10:59:16 +00:00
cliApp *cli.App
2022-07-22 14:09:34 +00:00
}
2023-08-15 09:47:52 +00:00
func NewApp(
ghClient *github.Client,
) *App {
2023-08-15 10:59:16 +00:00
a := &action{
ghClient: ghClient,
}
2022-07-22 14:09:34 +00:00
cliApp := &cli.App{
Name: name,
Usage: usage,
Commands: []*cli.Command{
{
2022-08-16 03:34:55 +00:00
Name: commandRunName,
Usage: commandRunUsage,
2022-07-22 14:09:34 +00:00
Flags: []cli.Flag{
&cli.BoolFlag{
2022-08-16 03:34:55 +00:00
Name: flagVerboseName,
2022-07-22 14:09:34 +00:00
Aliases: aliasFlagVerbose,
2022-08-16 03:34:55 +00:00
Usage: flagVerboseUsage,
2022-07-22 14:09:34 +00:00
},
&cli.StringFlag{
2022-08-16 03:34:55 +00:00
Name: flagDepsFileName,
Usage: flagDepsFileUsage,
2022-07-22 15:50:51 +00:00
},
&cli.StringFlag{
2022-08-16 03:34:55 +00:00
Name: flagDepsURLName,
Usage: flagDepsURLUsage,
2022-07-22 14:09:34 +00:00
},
&cli.BoolFlag{
Name: flagDryRun,
2022-08-16 03:34:55 +00:00
Usage: flagDryRunName,
2022-07-22 14:09:34 +00:00
},
},
Action: a.Run,
},
2023-08-15 10:59:16 +00:00
{
Name: commandOverlookName,
Usage: commandOverlookUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: flagVerboseName,
Aliases: aliasFlagVerbose,
Usage: flagVerboseUsage,
},
},
Action: a.Overlook,
},
2022-07-22 14:09:34 +00:00
},
Action: a.RunHelp,
}
return &App{
2023-08-15 10:59:16 +00:00
cliApp: cliApp,
2022-07-22 14:09:34 +00:00
}
}
func (a *App) Run() {
if err := a.cliApp.Run(os.Args); err != nil {
color.PrintAppError(name, err.Error())
}
}