From 7b1f513acf0c5f4f09a3d91f15d43bae13bc47be Mon Sep 17 00:00:00 2001 From: Akshit42-hue Date: Thu, 13 Oct 2022 22:03:34 +0530 Subject: [PATCH 1/2] added_command_to_print_complete_recipe Signed-off-by: Akshit42-hue --- cmd/cli/main.go | 19 +++++++++++++++++++ pkg/registry/registry.go | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 4e95795..366290b 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..4de8670 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{} From 2097fb12420285e3a8f183a6c0e35b837b313814 Mon Sep 17 00:00:00 2001 From: Akshit42-hue Date: Mon, 31 Oct 2022 12:31:32 +0530 Subject: [PATCH 2/2] fix_ci Signed-off-by: Akshit42-hue --- cmd/cli/main.go | 6 +++--- pkg/registry/registry.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 366290b..cec9e0d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -174,9 +174,9 @@ var ( } recipeCmd = &cobra.Command{ - Use: "recipe [Name]", + Use: "recipe [Name]", Short: "Recipe details", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { reg, err := registry.New(config.ConfigDir) if err != nil { @@ -188,7 +188,7 @@ var ( } fmt.Println(s) return nil - }, + }, } argsCmd = &cobra.Command{ diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index 4de8670..b2430f5 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -123,11 +123,11 @@ func (kr *KbrewRegistry) FetchDetailRecipe(appName string) (string, error) { if len(info) == 0 { return "", fmt.Errorf("no recipe found for %s", appName) } - path := info[0].Path + path := info[0].Path // fs,e os.OpenFile(path) data, err := os.ReadFile(path) - check(err) - //fmt.Print(string(dat)) + check(err) + //fmt.Print(string(dat)) return string(data), nil }