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

feat(lql): add option to generate empty lql file #1335

Merged
merged 4 commits into from
Oct 13, 2023
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
32 changes: 23 additions & 9 deletions cli/cmd/lql.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ import (

var (
queryCmdState = struct {
End string
File string
Limit int
Range string
Start string
URL string
ValidateOnly bool
FailOnCount string
End string
File string
Limit int
Range string
Start string
URL string
ValidateOnly bool
FailOnCount string
EmptyTemplate bool
// create, update validate from library
CURVFromLibrary string
}{}
Expand Down Expand Up @@ -191,6 +192,12 @@ func init() {
"fail_on_count", "",
"fail if the results from a query match the provided expression (e.g. '>0')",
)
// empty template flag
queryRunCmd.Flags().BoolVar(
&queryCmdState.EmptyTemplate,
"empty", false,
"start $EDITOR with empty file",
)
}

func setQuerySourceFlags(cmds ...*cobra.Command) {
Expand Down Expand Up @@ -295,7 +302,7 @@ func inputQueryFromEditor(action string) (query string, err error) {
FileName: "query*.yaml",
}

if action == "create" || action == "run" {
if (action == "create" || action == "run") && !queryCmdState.EmptyTemplate {
prompt.Default = `queryId: YourQueryID
queryText: |-
{
Expand All @@ -311,6 +318,10 @@ queryText: |-
}`
prompt.HideDefault = true
prompt.AppendDefault = true
} else if (action == "create" || action == "run") && queryCmdState.EmptyTemplate {
prompt.Default = ``
prompt.HideDefault = true
prompt.AppendDefault = true
}

err = survey.AskOne(prompt, &query)
Expand Down Expand Up @@ -402,6 +413,9 @@ func runQuery(cmd *cobra.Command, args []string) error {
if queryCmdState.ValidateOnly {
naFlag = "validate_only"
}
if queryCmdState.EmptyTemplate {
naFlag = "empty"
}
if naFlag != "" {
return errors.New(
fmt.Sprintf(
Expand Down
1 change: 1 addition & 0 deletions integration/test_resources/help/query_run
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Aliases:
run, execute

Flags:
--empty start $EDITOR with empty file
--end string end time for query (default "now")
--fail_on_count string fail if the results from a query match the provided expression (e.g. '>0')
-f, --file string path to a query to run
Expand Down