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

82 lines
1.4 KiB
Go
Raw Normal View History

2022-07-22 14:09:34 +00:00
package cli
import (
"os"
"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
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 {
cliApp *cli.App
}
func NewApp() *App {
a := &action{}
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,
},
},
Action: a.RunHelp,
}
return &App{
cliApp: cliApp,
}
}
func (a *App) Run() {
if err := a.cliApp.Run(os.Args); err != nil {
color.PrintAppError(name, err.Error())
}
}