forked from toolshed/abra
refactor!: cobra migrate
This commit is contained in:
@ -1,34 +1,38 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var recipeFetchCommand = cli.Command{
|
||||
Name: "fetch",
|
||||
Usage: "Fetch recipe(s)",
|
||||
Aliases: []string{"f"},
|
||||
UsageText: "abra recipe fetch [<recipe>] [options]",
|
||||
Description: "Retrieves all recipes if no <recipe> argument is passed",
|
||||
Before: internal.SubCommandBefore,
|
||||
ShellComplete: autocomplete.RecipeNameComplete,
|
||||
HideHelp: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
recipeName := cmd.Args().First()
|
||||
r := recipe.Get(recipeName)
|
||||
var RecipeFetchCommand = &cobra.Command{
|
||||
Use: "fetch [recipe] [flags]",
|
||||
Aliases: []string{"f"},
|
||||
Short: "Fetch recipe(s)",
|
||||
Long: "Retrieves all recipes if no [recipe] argument is passed.",
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return autocomplete.RecipeNameComplete()
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var recipeName string
|
||||
if len(args) > 0 {
|
||||
recipeName = args[0]
|
||||
}
|
||||
|
||||
if recipeName != "" {
|
||||
internal.ValidateRecipe(cmd)
|
||||
r := internal.ValidateRecipe(args, cmd.Name())
|
||||
if err := r.Ensure(false, false); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
catalogue, err := recipe.ReadRecipeCatalogue(internal.Offline)
|
||||
@ -44,7 +48,5 @@ var recipeFetchCommand = cli.Command{
|
||||
}
|
||||
catlBar.Add(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user