refactor: urfave v3
This commit is contained in:
@ -9,12 +9,12 @@ import (
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// ValidateRecipe ensures the recipe arg is valid.
|
||||
func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
recipeName := c.Args().First()
|
||||
func ValidateRecipe(cmd *cli.Command) recipe.Recipe {
|
||||
recipeName := cmd.Args().First()
|
||||
|
||||
if recipeName == "" && !NoInput {
|
||||
var recipes []string
|
||||
@ -54,7 +54,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
}
|
||||
|
||||
if recipeName == "" {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))
|
||||
ShowSubcommandHelpAndError(cmd, errors.New("no recipe name provided"))
|
||||
}
|
||||
|
||||
chosenRecipe := recipe.Get(recipeName)
|
||||
@ -64,7 +64,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
}
|
||||
_, err = chosenRecipe.GetComposeConfig(nil)
|
||||
if err != nil {
|
||||
if c.Command.Name == "generate" {
|
||||
if cmd.Name == "generate" {
|
||||
if strings.Contains(err.Error(), "missing a compose") {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -83,11 +83,11 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
}
|
||||
|
||||
// ValidateApp ensures the app name arg is valid.
|
||||
func ValidateApp(c *cli.Context) app.App {
|
||||
appName := c.Args().First()
|
||||
func ValidateApp(cmd *cli.Command) app.App {
|
||||
appName := cmd.Args().First()
|
||||
|
||||
if appName == "" {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no app provided"))
|
||||
ShowSubcommandHelpAndError(cmd, errors.New("no app provided"))
|
||||
}
|
||||
|
||||
app, err := app.Get(appName)
|
||||
@ -101,8 +101,8 @@ func ValidateApp(c *cli.Context) app.App {
|
||||
}
|
||||
|
||||
// ValidateDomain ensures the domain name arg is valid.
|
||||
func ValidateDomain(c *cli.Context) string {
|
||||
domainName := c.Args().First()
|
||||
func ValidateDomain(cmd *cli.Command) string {
|
||||
domainName := cmd.Args().First()
|
||||
|
||||
if domainName == "" && !NoInput {
|
||||
prompt := &survey.Input{
|
||||
@ -115,7 +115,7 @@ func ValidateDomain(c *cli.Context) string {
|
||||
}
|
||||
|
||||
if domainName == "" {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no domain provided"))
|
||||
ShowSubcommandHelpAndError(cmd, errors.New("no domain provided"))
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as domain argument", domainName)
|
||||
@ -124,10 +124,10 @@ func ValidateDomain(c *cli.Context) string {
|
||||
}
|
||||
|
||||
// ValidateSubCmdFlags ensures flag order conforms to correct order
|
||||
func ValidateSubCmdFlags(c *cli.Context) bool {
|
||||
for argIdx, arg := range c.Args().Slice() {
|
||||
func ValidateSubCmdFlags(cmd *cli.Command) bool {
|
||||
for argIdx, arg := range cmd.Args().Slice() {
|
||||
if !strings.HasPrefix(arg, "--") {
|
||||
for _, flag := range c.Args().Slice()[argIdx:] {
|
||||
for _, flag := range cmd.Args().Slice()[argIdx:] {
|
||||
if strings.HasPrefix(flag, "--") {
|
||||
return false
|
||||
}
|
||||
@ -138,8 +138,8 @@ func ValidateSubCmdFlags(c *cli.Context) bool {
|
||||
}
|
||||
|
||||
// ValidateServer ensures the server name arg is valid.
|
||||
func ValidateServer(c *cli.Context) string {
|
||||
serverName := c.Args().First()
|
||||
func ValidateServer(cmd *cli.Command) string {
|
||||
serverName := cmd.Args().First()
|
||||
|
||||
serverNames, err := config.ReadServerNames()
|
||||
if err != nil {
|
||||
@ -164,11 +164,11 @@ func ValidateServer(c *cli.Context) string {
|
||||
}
|
||||
|
||||
if serverName == "" {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no server provided"))
|
||||
ShowSubcommandHelpAndError(cmd, errors.New("no server provided"))
|
||||
}
|
||||
|
||||
if !matched {
|
||||
ShowSubcommandHelpAndError(c, errors.New("server doesn't exist?"))
|
||||
ShowSubcommandHelpAndError(cmd, errors.New("server doesn't exist?"))
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as server argument", serverName)
|
||||
|
Reference in New Issue
Block a user