Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
neilnaveen and coderabbitai[bot] committed Oct 23, 2024
1 parent 926c137 commit 640953d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/query/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (o *options) AddFlags(cmd *cobra.Command) {

func (o *options) Run(cmd *cobra.Command, args []string) error {
script := strings.Join(args, " ")

if strings.TrimSpace(script) == "" {
return fmt.Errorf("script cannot be empty")
}
httpClient := &http.Client{}
addr := os.Getenv("BITBOMDEV_ADDR")
if addr == "" {
Expand Down Expand Up @@ -64,7 +68,7 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {

count := 0
for _, node := range res.Msg.Nodes {
if count > o.maxOutput {
if count >= o.maxOutput {
break
}

Expand All @@ -75,8 +79,12 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("failed to marshal node metadata: %w", err)
}
if _, err := os.Stat(o.outputdir); err != nil {
return fmt.Errorf("output directory does not exist: %w", err)
if _, err := os.Stat(o.outputdir); os.IsNotExist(err) {
if err := os.MkdirAll(o.outputdir, os.ModePerm); err != nil {
return fmt.Errorf("failed to create output directory: %w", err)
}
} else if err != nil {
return fmt.Errorf("failed to check output directory: %w", err)
}

filePath := filepath.Join(o.outputdir, tools.SanitizeFilename(node.Name)+".json")
Expand Down Expand Up @@ -129,7 +137,7 @@ func New(storage graph.Storage) *cobra.Command {
cmd := &cobra.Command{
Use: "custom [script]",
Short: "Quer dependencies and dependents of a project",
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
RunE: o.Run,
DisableAutoGenTag: true,
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/query/globsearch/globsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("query failed: %v", err)
}

if len(res.Msg.Nodes) == 0 {
fmt.Println("No nodes found matching pattern:", pattern)
return nil
}

// Print dependencies
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Type", "ID"})
Expand Down

0 comments on commit 640953d

Please sign in to comment.