diff --git a/cmd/filterList.go b/cmd/filterList.go index 3e2dc61..b23f667 100644 --- a/cmd/filterList.go +++ b/cmd/filterList.go @@ -18,10 +18,11 @@ package cmd import ( "fmt" "os" - "pb/pkg/model" "strings" "time" + "pb/pkg/model" + "github.com/spf13/cobra" ) diff --git a/cmd/query.go b/cmd/query.go index 4db92e3..9e20e6f 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -20,10 +20,12 @@ import ( "fmt" "io" "os" - "pb/pkg/config" - // "pb/pkg/model" "strings" "time" + + "pb/pkg/config" + // "pb/pkg/model" + //! This dependancy is required by the interactive flag Do not remove // tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" @@ -41,7 +43,7 @@ var ( // save filter flags saveFilterFlag = "save-as" saveFilterShort = "s" - //save filter with time flags + // save filter with time flags saveFilterTimeFlag = "with-time" saveFilterTimeShort = "w" @@ -66,7 +68,7 @@ var query = &cobra.Command{ fmt.Printf("Example:\n pb query run \"select * from frontend\" --from=10m --to=now\n") return nil } - + query = args[0] start, err := command.Flags().GetString(startFlag) @@ -85,7 +87,7 @@ var query = &cobra.Command{ end = defaultEnd } - //TODO: Interactive Flag disabled + // TODO: Interactive Flag disabled // interactive, err := command.Flags().GetBool(interactiveFlag) // if err != nil { // return err @@ -107,7 +109,7 @@ var query = &cobra.Command{ } filterNameTrimmed := strings.Trim(filterName, " ") - //TODO: Interactive Flag disabled + // TODO: Interactive Flag disabled // if interactive { // p := tea.NewProgram(model.NewQueryModel(DefaultProfile, query, startTime, endTime), tea.WithAltScreen()) // if _, err := p.Run(); err != nil { @@ -126,7 +128,6 @@ var query = &cobra.Command{ } 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) @@ -211,7 +212,6 @@ func parseTime(start, end string) (time.Time, time.Time, error) { // create a request body for saving filter without time_filter func createFilter(query string, filterName string) (err error) { - userConfig, err := config.ReadConfigFromFile() if err != nil { return err @@ -250,7 +250,6 @@ func createFilter(query string, filterName string) (err error) { saveFilterToServer(finalQuery) return err - } // create a request body for saving filter with time_filter diff --git a/main.go b/main.go index e974f11..ed45009 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ package main import ( "errors" "os" + "pb/cmd" "pb/pkg/config" @@ -142,7 +143,7 @@ func main() { } config.WriteConfigToFile(&conf) } else { - //updates the demo profile for existing users + // updates the demo profile for existing users _, exists := previousConfig.Profiles["demo"] if exists { conf := config.Config{ diff --git a/pkg/model/savedFilters.go b/pkg/model/savedFilters.go index e40f65e..88e1ae1 100644 --- a/pkg/model/savedFilters.go +++ b/pkg/model/savedFilters.go @@ -19,10 +19,11 @@ import ( "fmt" "io" "net/http" - "pb/pkg/config" "strings" "time" + "pb/pkg/config" + "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" @@ -116,8 +117,10 @@ func (d itemDelegate) FullHelp() [][]key.Binding { } } -var selectedFilterApply item -var selectedFilterDelete item +var ( + selectedFilterApply item + selectedFilterDelete item +) func (i item) Title() string { return fmt.Sprintf("Filter:%s, Query:%s", i.title, i.desc) } @@ -173,7 +176,6 @@ func (m modelFilter) View() string { // Interactive list for the user to display all the available filters (only saved SQL filters ) func UiApp() *tea.Program { - userConfig, err := config.ReadConfigFromFile() if err != nil { fmt.Println("Error reading Default Profile") @@ -192,12 +194,10 @@ func UiApp() *tea.Program { m.list.Title = fmt.Sprintf("Saved Filters for User: %s", userProfile.Username) return tea.NewProgram(m, tea.WithAltScreen()) - } // fetchFilters fetches filters from the server and sends them to the channel func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { - endpoint := fmt.Sprintf("%s/%s/%s", profile.URL, "api/v1/filters", profile.Username) req, err := http.NewRequest("GET", endpoint, nil) if err != nil { @@ -253,7 +253,6 @@ func fetchFilters(client *http.Client, profile *config.Profile) []list.Item { } } return userFilters - } // returns the selected filter by user in the iteractive list