Skip to content

Commit

Permalink
Error handling improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Koustavd18 committed Jul 29, 2024
1 parent 9c86574 commit 0376de1
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ var (
defaultEnd = "now"

// save filter flags
saveFilterFlag = "save-as"
saveFilterShort = "s"
saveFilterFlag = "save-as"
saveFilterShort = "s"
//save filter with time flags
saveFilterTimeFlag = "with-time"
saveFilterTimeFlag = "with-time"
saveFilterTimeShort = "w"

interactiveFlag = "interactive"
Expand Down Expand Up @@ -104,12 +104,8 @@ var query = &cobra.Command{
if err != nil {
return err
}
if filterName=="" {
filterName = "DEFAULT_FILTER_NAME"
}
filterNameTrimmed := strings.Trim(filterName, " ")


if interactive {
p := tea.NewProgram(model.NewQueryModel(DefaultProfile, query, startTime, endTime), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
Expand All @@ -120,21 +116,24 @@ var query = &cobra.Command{
}

// Checks if there is filter name which is not empty. Empty filter name wont be allowed
if len(filterNameTrimmed) == 0 {
if command.Flags().Changed(saveFilterFlag) {
if filterName == "" || len(filterNameTrimmed) == 0 || filterName == "=" {
fmt.Println("please provide a filter name")
command.Help()
return nil
} else if filterName != "" {
if keepTime {
createFilterWithTime(query, filterNameTrimmed, start, end)

} else {
// if there is no keep time filter pass empty values for startTime and endTime
createFilter(query, filterNameTrimmed)
}
}
} else if filterName == "" && keepTime {
fmt.Println("please provide a filter name")
command.Help()
return nil
} else if filterName != "DEFAULT_FILTER_NAME" {
if keepTime {
createFilterWithTime(query, filterNameTrimmed, start, end)

} else {
// if there is no keep time filter pass empty values for startTime and endTime
createFilter(query, filterNameTrimmed)
}
} else if filterName == "DEFAULT_FILTER_NAME" && keepTime{
fmt.Println("please provide a filter name")
command.Help()
return nil
}

client := DefaultClient()
Expand All @@ -143,11 +142,11 @@ var query = &cobra.Command{
}

var QueryCmd = func() *cobra.Command {
query.Flags().BoolP(saveFilterTimeFlag, saveFilterTimeShort,false, "Save the time range associated in the query to the filter") // save time for a filter flag; default value = false (boolean type)
query.Flags().BoolP(saveFilterTimeFlag, saveFilterTimeShort, false, "Save the time range associated in the query to the filter") // save time for a filter flag; default value = false (boolean type)
query.Flags().BoolP(interactiveFlag, interactiveFlagShort, false, "open the query result in interactive mode")
query.Flags().StringP(startFlag, startFlagShort, defaultStart, "Start time for query. Takes date as '2024-10-12T07:20:50.52Z' or string like '10m', '1hr'")
query.Flags().StringP(endFlag, endFlagShort, defaultEnd, "End time for query. Takes date as '2024-10-12T07:20:50.52Z' or 'now'")
query.Flags().StringP(saveFilterFlag, saveFilterShort , "", "Save a query filter") // save filter flag. Default value = FILTER_NAME (type string)
query.Flags().StringP(saveFilterFlag, saveFilterShort, "", "Save a query filter") // save filter flag. Default value = FILTER_NAME (type string)
return query
}()

Expand Down

0 comments on commit 0376de1

Please sign in to comment.