Skip to content

Commit

Permalink
chore: Added support for reading quey from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Jul 10, 2024
1 parent c11bef6 commit 8d754d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/fatih/color"
"os"
"regexp"
"strconv"
"time"

"github.com/fatih/color"

log "github.com/sirupsen/logrus"

"github.com/newrelic/newrelic-cli/internal/cli"
Expand Down
3 changes: 2 additions & 1 deletion internal/install/recipes/process_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

"github.com/newrelic/newrelic-cli/internal/install/execution"
"golang.org/x/exp/slices"

"github.com/newrelic/newrelic-cli/internal/install/execution"

"github.com/shirou/gopsutil/v3/process"
log "github.com/sirupsen/logrus"

Expand Down
16 changes: 16 additions & 0 deletions internal/nrql/command_query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package nrql

import (
"errors"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -29,6 +32,19 @@ issue the query against.
PreRun: client.RequireClient,
Run: func(cmd *cobra.Command, args []string) {
accountID := configAPI.RequireActiveProfileAccountID()

_, err := os.Stat(query)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatal(err)
} else {
// query points to a file/file descriptor
fileBytes, readErr := os.ReadFile(query)
if readErr != nil {
log.Fatal(readErr)
}
query = string(fileBytes)
}

result, err := client.NRClient.Nrdb.QueryWithContext(utils.SignalCtx, accountID, nrdb.NRQL(query))
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 8d754d6

Please sign in to comment.