Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
Expand Down
101 changes: 27 additions & 74 deletions cmd/queryList.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"net/http"
"os"
"pb/pkg/config"
internalHTTP "pb/pkg/http"
"pb/pkg/model"
Expand All @@ -36,7 +35,7 @@ var SavedQueryList = &cobra.Command{
Short: "List of saved queries",
Long: "\nShow the list of saved queries for active user",
PreRunE: PreRunDefaultProfile,
Run: func(_ *cobra.Command, _ []string) {
RunE: func(_ *cobra.Command, _ []string) error {
client := internalHTTP.DefaultClient(&DefaultProfile)

// Check if the output flag is set
Expand All @@ -63,11 +62,11 @@ var SavedQueryList = &cobra.Command{
jsonOutput, err := json.MarshalIndent(userSavedQueries, "", " ")
if err != nil {
fmt.Println("Error converting saved queries to JSON:", err)
return
return err
}
if string(jsonOutput) == "null" {
fmt.Println("[]")
return
return nil
}
fmt.Println(string(jsonOutput))
} else {
Expand Down Expand Up @@ -96,24 +95,27 @@ var SavedQueryList = &cobra.Command{
}
// Print all titles as a single line, comma-separated
fmt.Println(strings.Join(filterDetails, " "))
return
return nil

}

// Normal Saved Queries Menu if output flag not set
p := model.SavedQueriesMenu()
if _, err := p.Run(); err != nil {
os.Exit(1)
return err
}

a := model.QueryToApply()
d := model.QueryToDelete()
if a.Stream() != "" {
savedQueryToPbQuery(a.Stream(), a.StartTime(), a.EndTime())
if err := savedQueryToPbQuery(a.Stream(), a.StartTime(), a.EndTime()); err != nil {
return err
}
}
if d.SavedQueryID() != "" {
deleteSavedQuery(&client, d.SavedQueryID(), d.Title())
}
return nil
},
}

Expand All @@ -137,73 +139,25 @@ func deleteSavedQuery(client *internalHTTP.HTTPClient, savedQueryID, title strin
}
}

// Convert a saved query to executable pb query
func savedQueryToPbQuery(query string, start string, end string) {
var timeStamps string
if start == "" || end == "" {
timeStamps = ``
} else {
startFormatted := formatToRFC3339(start)
endFormatted := formatToRFC3339(end)
timeStamps = ` --from=` + startFormatted + ` --to=` + endFormatted
}
_ = `pb query run ` + query + timeStamps
}

// Parses all UTC time format from string to time interface
func parseTimeToFormat(input string) (time.Time, error) {
// List of possible formats
formats := []string{
time.RFC3339,
"2006-01-02 15:04:05",
"2006-01-02",
"01/02/2006 15:04:05",
"02-Jan-2006 15:04:05 MST",
"2006-01-02T15:04:05Z",
"02-Jan-2006",
// Convert a saved query to executable pb query and print results to terminal
func savedQueryToPbQuery(sqlQuery string, start string, end string) error {
if start == "" {
start = "1h"
}

var err error
var t time.Time

for _, format := range formats {
t, err = time.Parse(format, input)
if err == nil {
return t, nil
}
if end == "" {
end = "now"
}

return t, fmt.Errorf("unable to parse time: %s", input)
}

// Converts to RFC3339
func convertTime(input string) (string, error) {
t, err := parseTimeToFormat(input)
if err != nil {
return "", err
}
sqlQuery = quoteStreamNames(sqlQuery)
sqlQuery = quoteFieldsWithDots(sqlQuery)

return t.Format(time.RFC3339), nil
}
fmt.Printf("Query: %s\n", sqlQuery)

// Converts User inputted time to string type RFC3339 time
func formatToRFC3339(time string) string {
var formattedTime string
if len(strings.Fields(time)) > 1 {
newTime := strings.Fields(time)[0:2]
rfc39990time, err := convertTime(strings.Join(newTime, " "))
if err != nil {
fmt.Println("error formatting time")
}
formattedTime = rfc39990time
} else {
rfc39990time, err := convertTime(time)
if err != nil {
fmt.Println("error formatting time")
}
formattedTime = rfc39990time
}
return formattedTime
client := internalHTTP.DefaultClient(&DefaultProfile)
stopSpinner := startSpinner()
err := fetchData(&client, sqlQuery, start, end, "")
stopSpinner()
return err
}

func init() {
Expand Down Expand Up @@ -253,19 +207,18 @@ func fetchFilters(client *http.Client, profile *config.Profile) []Item {
// This returns only the SQL type filters
var userSavedQueries []Item
for _, filter := range filters {

queryBytes, _ := json.Marshal(filter.Query.FilterQuery)

if filter.Query.FilterQuery == nil {
continue
}
userSavedQuery := Item{
ID: filter.FilterID,
Title: filter.FilterName,
Stream: filter.StreamName,
Desc: string(queryBytes),
Desc: *filter.Query.FilterQuery,
From: filter.TimeFilter.From,
To: filter.TimeFilter.To,
}
userSavedQueries = append(userSavedQueries, userSavedQuery)

}
return userSavedQueries
}
29 changes: 22 additions & 7 deletions cmd/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,38 @@
package cmd

import (
"pb/pkg/ui"

"github.com/charmbracelet/lipgloss"
)

// styling for cli outputs
// Styles for the cobra command CLI outputs (prompts, error messages, list
// items rendered outside the bubbletea TUI). Sourced from the shared
// ui.Palette so any palette change auto-propagates here.
//
// Names kept stable for backwards compatibility with existing call sites
// across cmd/ and pkg/model/.
var (
FocusPrimary = lipgloss.AdaptiveColor{Light: "16", Dark: "226"}
FocusSecondary = lipgloss.AdaptiveColor{Light: "18", Dark: "220"}
// FocusPrimary / FocusSecondary used to be yellow (ANSI 226/220). Now
// brand indigo — same role (selected / active item highlight) but
// matches the rest of the design system.
FocusPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent })
FocusSecondary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent2 })

StandardPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Body })
StandardSecondary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Mute })

StandardPrimary = lipgloss.AdaptiveColor{Light: "235", Dark: "255"}
StandardSecondary = lipgloss.AdaptiveColor{Light: "238", Dark: "254"}
StandardStyle = lipgloss.NewStyle().Foreground(StandardPrimary)
StandardStyleBold = lipgloss.NewStyle().Foreground(StandardPrimary).Bold(true)
StandardStyleAlt = lipgloss.NewStyle().Foreground(StandardSecondary)
SelectedStyle = lipgloss.NewStyle().Foreground(FocusPrimary).Bold(true)
SelectedStyleAlt = lipgloss.NewStyle().Foreground(FocusSecondary)
SelectedItemOuter = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderLeft(true).PaddingLeft(1).BorderForeground(FocusPrimary)
ItemOuter = lipgloss.NewStyle().PaddingLeft(1)
SelectedItemOuter = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
BorderLeft(true).
PaddingLeft(1).
BorderForeground(FocusPrimary)
ItemOuter = lipgloss.NewStyle().PaddingLeft(1)

StyleBold = lipgloss.NewStyle().Bold(true)
)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ go 1.25.0
toolchain go1.25.4

require (
github.com/alecthomas/chroma/v2 v2.24.1
github.com/apache/arrow/go/v13 v13.0.0
github.com/briandowns/spinner v1.23.1
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/lipgloss v0.12.1
github.com/dustin/go-humanize v1.0.1
github.com/gofrs/flock v0.12.1
github.com/guptarohit/asciigraph v0.9.0
github.com/manifoldco/promptui v0.9.0
github.com/oklog/ulid/v2 v2.1.0
github.com/olekukonko/tablewriter v0.0.5
Expand Down Expand Up @@ -55,6 +57,7 @@ require (
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/dlclark/regexp2 v1.12.0 // indirect
github.com/docker/cli v25.0.1+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v25.0.6+incompatible // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/Microsoft/hcsshim v0.11.7 h1:vl/nj3Bar/CvJSYo7gIQPyRWc9f3c6IeSNavBTSZ
github.com/Microsoft/hcsshim v0.11.7/go.mod h1:MV8xMfmECjl5HdO7U/3/hFVnkmSBjAjmA09d4bExKcU=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/OJnIp5u0s1SbQ8dVfLCZJsnvazdBP5hS4iRs=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/alecthomas/chroma/v2 v2.24.1 h1:m5ffpfZbIb++k8AqFEKy9uVgY12xIQtBsQlc6DfZJQM=
github.com/alecthomas/chroma/v2 v2.24.1/go.mod h1:l+ohZ9xRXIbGe7cIW+YZgOGbvuVLjMps/FYN/CwuabI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apache/arrow/go/v13 v13.0.0 h1:kELrvDQuKZo8csdWYqBQfyi431x6Zs/YJTEgUuSVcWk=
Expand Down Expand Up @@ -108,6 +110,8 @@ github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 h1:aB
github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2/go.mod h1:WHNsWjnIn2V1LYOrME7e8KxSeKunYHsxEm4am0BUtcI=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8=
github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/cli v25.0.1+incompatible h1:mFpqnrS6Hsm3v1k7Wa/BO23oz0k121MTbTO1lpcGSkU=
github.com/docker/cli v25.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
Expand Down Expand Up @@ -233,6 +237,8 @@ github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/guptarohit/asciigraph v0.9.0 h1:MvCSRRVkT2XvU1IO6n92o7l7zqx1DiFaoszOUZQztbY=
github.com/guptarohit/asciigraph v0.9.0/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
11 changes: 6 additions & 5 deletions pkg/model/credential/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ package credential

import (
"pb/pkg/model/button"
"pb/pkg/ui"
"strings"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

// Default Style for this widget
// Default Style for this widget — theme-derived; yellow no more.
var (
FocusPrimary = lipgloss.AdaptiveColor{Light: "16", Dark: "226"}
FocusSecondary = lipgloss.AdaptiveColor{Light: "18", Dark: "220"}
FocusPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent })
FocusSecondary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent2 })

StandardPrimary = lipgloss.AdaptiveColor{Light: "235", Dark: "255"}
StandardSecondary = lipgloss.AdaptiveColor{Light: "238", Dark: "254"}
StandardPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Body })
StandardSecondary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Mute })

focusedStyle = lipgloss.NewStyle().Foreground(FocusPrimary)
blurredStyle = lipgloss.NewStyle().Foreground(StandardSecondary)
Expand Down
17 changes: 9 additions & 8 deletions pkg/model/defaultprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ import (
"fmt"
"io"
"pb/pkg/config"
"pb/pkg/ui"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

var (
// FocusPrimary is the primary focus color
FocusPrimary = lipgloss.AdaptiveColor{Light: "16", Dark: "226"}
// FocusSecondry is the secondry focus color
FocusSecondry = lipgloss.AdaptiveColor{Light: "18", Dark: "220"}
// StandardPrimary is the primary standard color
StandardPrimary = lipgloss.AdaptiveColor{Light: "235", Dark: "255"}
// StandardSecondary is the secondary standard color
StandardSecondary = lipgloss.AdaptiveColor{Light: "238", Dark: "254"}
// FocusPrimary is the primary focus color (brand indigo).
FocusPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent })
// FocusSecondry is the secondary focus color.
FocusSecondry = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Accent2 })
// StandardPrimary is the primary standard color.
StandardPrimary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Body })
// StandardSecondary is the secondary standard color.
StandardSecondary = ui.Adaptive(func(p ui.Palette) lipgloss.Color { return p.Mute })

focusTitleStyle = lipgloss.NewStyle().Foreground(FocusPrimary)
focusDescStyle = lipgloss.NewStyle().Foreground(FocusSecondry)
Expand Down
Loading
Loading