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
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -212,6 +230,7 @@ func init() {
rootCmd.AddCommand(analyticsCmd)
rootCmd.AddCommand(completionCmd)
rootCmd.AddCommand(infoCmd)
rootCmd.AddCommand(recipeCmd)

infoCmd.AddCommand(argsCmd)

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

Choose a reason for hiding this comment

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

It should not panic. Rather return and handle 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{}
Expand Down