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

Add outputing for queries #110

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
15 changes: 15 additions & 0 deletions cmd/leaderboard/allKeys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ type options struct {
storage graph.Storage
maxOutput int
showInfo bool // New field to control the display of the Info column
saveQuery string
}

func (o *options) AddFlags(cmd *cobra.Command) {
cmd.Flags().IntVar(&o.maxOutput, "max-getMetadata", 10, "max getMetadata length")
cmd.Flags().BoolVar(&o.showInfo, "show-info", true, "display the info column")
cmd.Flags().StringVar(&o.saveQuery, "save-query", "", "save the query to a specific file")
}

func (o *options) Run(_ *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -54,6 +56,15 @@ func (o *options) Run(_ *cobra.Command, _ []string) error {
}
table.SetHeader(headers)

var f *os.File
if o.saveQuery != "" {
f, err = os.Create(o.saveQuery)
if err != nil {
return err
}
defer f.Close()
}

for index, node := range res.Msg.Nodes {
if index >= o.maxOutput {
break
Expand All @@ -74,6 +85,10 @@ func (o *options) Run(_ *cobra.Command, _ []string) error {

// Append the row to the table
table.Append(row)

if o.saveQuery != "" {
f.WriteString(node.Name + "\n")
}
}

table.Render()
Expand Down
15 changes: 15 additions & 0 deletions cmd/leaderboard/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type options struct {
all bool
maxOutput int
showInfo bool // New field to control the display of the Info column
saveQuery string
}

type query struct {
Expand All @@ -33,6 +34,7 @@ func (o *options) AddFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&o.all, "all", false, "show the queries getMetadata for each node")
cmd.Flags().IntVar(&o.maxOutput, "max-getMetadata", 10, "max getMetadata length")
cmd.Flags().BoolVar(&o.showInfo, "show-info", true, "display the info column")
cmd.Flags().StringVar(&o.saveQuery, "save-query", "", "save the query to a specific file")
}

func (o *options) Run(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -67,6 +69,15 @@ func (o *options) Run(_ *cobra.Command, args []string) error {
}
table.SetHeader(headers)

var f *os.File
if o.saveQuery != "" {
f, err = os.Create(o.saveQuery)
if err != nil {
return err
}
defer f.Close()
}

for index, q := range res.Msg.Queries {
if index >= o.maxOutput {
break
Expand Down Expand Up @@ -96,6 +107,10 @@ func (o *options) Run(_ *cobra.Command, args []string) error {

// Append the row to the table
table.Append(row)

if o.saveQuery != "" {
f.WriteString(q.Node.Name + "\n")
}
}
table.Render()
return nil
Expand Down
14 changes: 14 additions & 0 deletions cmd/query/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ type options struct {
visualizerAddr string
maxOutput int
showInfo bool
saveQuery string
}

func (o *options) AddFlags(cmd *cobra.Command) {
cmd.Flags().IntVar(&o.maxOutput, "max-getMetadata", 10, "max getMetadata length")
cmd.Flags().BoolVar(&o.visualize, "visualize", false, "visualize the query")
cmd.Flags().StringVar(&o.visualizerAddr, "addr", "8081", "address to run the visualizer on")
cmd.Flags().BoolVar(&o.showInfo, "show-info", true, "display the info column")
cmd.Flags().StringVar(&o.saveQuery, "save-query", "", "save the query to a specific file")
}

func (o *options) Run(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -74,6 +76,14 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {

// Build the rows
count := 0
var f *os.File
if o.saveQuery != "" {
f, err = os.Create(o.saveQuery)
if err != nil {
return err
}
defer f.Close()
}
for _, node := range res.Msg.Nodes {
if count >= o.maxOutput {
break
Expand All @@ -94,6 +104,10 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {

// Append the row to the table
table.Append(row)

if o.saveQuery != "" {
f.WriteString(node.Name + "\n")
}
count++
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/query/globsearch/globsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ type options struct {
storage graph.Storage
maxOutput int
showInfo bool // New field to control the display of the Info column
saveQuery string
}

func (o *options) AddFlags(cmd *cobra.Command) {
cmd.Flags().IntVar(&o.maxOutput, "max-output", 10, "maximum number of results to display")
cmd.Flags().BoolVar(&o.showInfo, "show-info", true, "display the info column")
cmd.Flags().StringVar(&o.saveQuery, "save-query", "", "save the query to a specific file")
}

func (o *options) Run(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -67,6 +69,15 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {
table.SetHeader(headers)

count := 0
var f *os.File
if o.saveQuery != "" {
f, err = os.Create(o.saveQuery)
if err != nil {
return err
}
defer f.Close()
}

for _, node := range res.Msg.Nodes {
if count >= o.maxOutput {
break
Expand All @@ -87,6 +98,10 @@ func (o *options) Run(cmd *cobra.Command, args []string) error {

// Append the row to the table
table.Append(row)

if o.saveQuery != "" {
f.WriteString(node.Name + "\n")
}
count++
}

Expand Down
Loading