Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command to print complete recipe #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added_command_to_print_complete_recipe
Signed-off-by: Akshit42-hue <patelakshit2025@gmail.com>
Akshit42-hue committed Oct 13, 2022
commit 7b1f513acf0c5f4f09a3d91f15d43bae13bc47be
19 changes: 19 additions & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
@@ -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)

23 changes: 23 additions & 0 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary comments

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{}