refactor!: cobra migrate
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
@ -9,23 +8,22 @@ import (
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/lint"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var recipeLintCommand = cli.Command{
|
||||
Name: "lint",
|
||||
Usage: "Lint a recipe",
|
||||
Aliases: []string{"l"},
|
||||
UsageText: "abra recipe lint <recipe> [options]",
|
||||
Flags: []cli.Flag{
|
||||
internal.OnlyErrorFlag,
|
||||
internal.ChaosFlag,
|
||||
var RecipeLintCommand = &cobra.Command{
|
||||
Use: "lint <recipe> [flags]",
|
||||
Short: "Lint a recipe",
|
||||
Aliases: []string{"l"},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return autocomplete.RecipeNameComplete()
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
ShellComplete: autocomplete.RecipeNameComplete,
|
||||
HideHelp: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
recipe := internal.ValidateRecipe(cmd)
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
recipe := internal.ValidateRecipe(args, cmd.Name())
|
||||
|
||||
if err := recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -52,7 +50,7 @@ var recipeLintCommand = cli.Command{
|
||||
var warnMessages []string
|
||||
for level := range lint.LintRules {
|
||||
for _, rule := range lint.LintRules[level] {
|
||||
if internal.OnlyErrors && rule.Level != "error" {
|
||||
if onlyError && rule.Level != "error" {
|
||||
log.Debugf("skipping %s, does not have level \"error\"", rule.Ref)
|
||||
continue
|
||||
}
|
||||
@ -116,7 +114,27 @@ var recipeLintCommand = cli.Command{
|
||||
log.Warnf("critical errors present in %s config", recipe.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
onlyError bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
RecipeLintCommand.Flags().BoolVarP(
|
||||
&internal.Chaos,
|
||||
"chaos",
|
||||
"C",
|
||||
false,
|
||||
"ignore uncommitted recipes changes",
|
||||
)
|
||||
|
||||
RecipeLintCommand.Flags().BoolVarP(
|
||||
&onlyError,
|
||||
"error",
|
||||
"e",
|
||||
false,
|
||||
"only show errors",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user