diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 4e95795..cec9e0d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -173,6 +173,24 @@ var ( }, } + recipeCmd = &cobra.Command{ + Use: "recipe [Name]", + Short: "Recipe details", + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + reg, err := registry.New(config.ConfigDir) + if err != nil { + return err + } + s, err := reg.FetchDetailRecipe(args[0]) + if err != nil { + return err + } + fmt.Println(s) + return nil + }, + } + argsCmd = &cobra.Command{ Use: "args [NAME]", Short: "Get arguments for an application", @@ -212,6 +230,7 @@ func init() { rootCmd.AddCommand(analyticsCmd) rootCmd.AddCommand(completionCmd) rootCmd.AddCommand(infoCmd) + rootCmd.AddCommand(recipeCmd) infoCmd.AddCommand(argsCmd) diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index c996815..b2430f5 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -108,6 +108,29 @@ func (kr *KbrewRegistry) FetchRecipe(appName string) (string, error) { return info[0].Path, nil } +func check(e error) { + if e != nil { + panic(e) + } +} + +func (kr *KbrewRegistry) FetchDetailRecipe(appName string) (string, error) { + // Iterate over all the registries + info, err := kr.Search(appName, true) + if err != nil { + return "", err + } + if len(info) == 0 { + return "", fmt.Errorf("no recipe found for %s", appName) + } + path := info[0].Path + // fs,e os.OpenFile(path) + data, err := os.ReadFile(path) + check(err) + //fmt.Print(string(dat)) + return string(data), nil +} + // Search returns app Info for give app func (kr *KbrewRegistry) Search(appName string, exactMatch bool) ([]Info, error) { result := []Info{}