diff --git a/cli/cmd/lql.go b/cli/cmd/lql.go index a3b9b7713..9f4033a1c 100644 --- a/cli/cmd/lql.go +++ b/cli/cmd/lql.go @@ -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 }{} @@ -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) { @@ -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: |- { @@ -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) @@ -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( diff --git a/integration/test_resources/help/query_run b/integration/test_resources/help/query_run index 0ce44e8ff..e71c5ed02 100644 --- a/integration/test_resources/help/query_run +++ b/integration/test_resources/help/query_run @@ -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