-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
andinternal/install/recipes/process_evaluator.go
3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/fatih/color" | ||
"os" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/fatih/color" | ||
|
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
_, err := os.Stat(query) | ||
if err != nil && !errors.Is(err, os.ErrNotExist) { | ||
log.Fatal(err) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
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: