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

chore: Added support for reading quey from a file #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lizard-boy
Copy link

Prior to this change, trying to do the following will result in an error:

$ newrelic nrql query --query <(cat some.nrql)

With this change, we support proper shell redirection. And, technically, the following will also work:

$ newrelic nrql query --query ./some.nrql

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds support for reading NRQL queries from files or through shell redirection in the newrelic nrql query command, enhancing its flexibility and usability.

  • Added file reading capability in internal/nrql/command_query.go for the --query flag
  • Implemented check to distinguish between file paths and direct query strings
  • Enabled support for shell redirection (e.g., <(cat some.nrql)) and direct file paths
  • Minor import reordering in internal/install/recipe_installer.go and internal/install/recipes/process_evaluator.go

3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Comment on lines 4 to +13
"context"
"errors"
"fmt"
"github.com/fatih/color"
"os"
"regexp"
"strconv"
"time"

"github.com/fatih/color"

Copy link

Choose a reason for hiding this comment

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

style: The import order has been changed, moving the standard library imports to the top and separating them from third-party imports with a blank line. This improves readability and follows Go best practices.

"os"
"regexp"
"strconv"
"time"

"github.com/fatih/color"
Copy link

Choose a reason for hiding this comment

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

style: An extra blank line has been added after the third-party imports. This is consistent with Go style guidelines and improves readability.

Comment on lines +36 to +38
_, err := os.Stat(query)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatal(err)
Copy link

Choose a reason for hiding this comment

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

style: Consider using os.IsNotExist(err) instead of !errors.Is(err, os.ErrNotExist) for better readability and consistency with Go's standard library

if readErr != nil {
log.Fatal(readErr)
}
query = string(fileBytes)
Copy link

Choose a reason for hiding this comment

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

style: Consider trimming whitespace from the query string to avoid potential issues with leading/trailing spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants