Skip to content

Commit

Permalink
Update clio to log errors to logger (#513)
Browse files Browse the repository at this point in the history
* update clio and other anchore deps

Signed-off-by: Alex Goodman <[email protected]>

* restore log on ui teardown

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Nov 8, 2024
1 parent 874f629 commit 722f43a
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 547 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ linters-settings:
gocritic:
enabled-checks:
- deferInLoop
- ruleguard

gosec:
excludes:
- G115
Expand Down
8 changes: 4 additions & 4 deletions cmd/quill/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func New(id clio.Identification) clio.Application {
WithConfigInRootHelp(). // --help on the root command renders the full application config in the help text
WithUIConstructor(
// select a UI based on the logging configuration and state of stdin (if stdin is a tty)
func(cfg clio.Config) ([]clio.UI, error) {
func(cfg clio.Config) (*clio.UICollection, error) {
noUI := ui.None()
if !cfg.Log.AllowUI(os.Stdin) {
return []clio.UI{noUI}, nil
return clio.NewUICollection(noUI), nil
}

return []clio.UI{
return clio.NewUICollection(
ui.New(false, cfg.Log.Quiet),
noUI,
}, nil
), nil
},
).
WithInitializers(
Expand Down
1 change: 0 additions & 1 deletion cmd/quill/cli/commands/extract_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func extractCertificates(binPath string, leaf bool) (string, error) {
buf := strings.Builder{}
certSet := strset.New()
for _, b := range decodedCerts {
b := b
singleBuf := strings.Builder{}
if err := pem.Encode(&singleBuf, &b); err != nil {
return "", err
Expand Down
12 changes: 6 additions & 6 deletions cmd/quill/cli/ui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ func (m *Handler) State() *State {
return m.state
}

func (m *Handler) handleInputPrompt(e partybus.Event) []tea.Model {
func (m *Handler) handleInputPrompt(e partybus.Event) ([]tea.Model, tea.Cmd) {
writer, err := event.ParseCLIInputPromptType(e)
if err != nil {
log.Warnf("unable to parse event: %+v", err)
return nil
return nil, nil
}

return []tea.Model{prompt.New(writer)}
return []tea.Model{prompt.New(writer)}, nil
}

func (m *Handler) handleTask(e partybus.Event) []tea.Model {
func (m *Handler) handleTask(e partybus.Event) ([]tea.Model, tea.Cmd) {
cmd, prog, err := event.ParseTaskType(e)
if err != nil {
log.Warnf("unable to parse event: %+v", err)
return nil
return nil, nil
}

return m.handleStagedProgressable(prog, taskprogress.Title{
Default: cmd.Title.Default,
Running: cmd.Title.WhileRunning,
Success: cmd.Title.OnSuccess,
Failed: cmd.Title.OnFail,
}, cmd.Context)
}, cmd.Context), nil
}

func (m *Handler) handleStagedProgressable(prog progress.StagedProgressable, title taskprogress.Title, context ...string) []tea.Model {
Expand Down
13 changes: 12 additions & 1 deletion cmd/quill/internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func (m *UI) Handle(e partybus.Event) error {
}

func (m *UI) Teardown(force bool) error {
defer func() {
// allow for traditional logging to resume now that the UI is shutting down
if logWrapper, ok := log.Get().(logger.Controller); ok {
logWrapper.SetOutput(os.Stderr)
}
}()

if !force {
m.handler.State().Running.Wait()
m.program.Quit()
Expand Down Expand Up @@ -154,7 +161,11 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}

for _, newModel := range m.handler.Handle(msg) {
newModels, cmd := m.handler.Handle(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
for _, newModel := range newModels {
if newModel == nil {
continue
}
Expand Down
74 changes: 38 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/anchore/quill

go 1.18
go 1.22.0

require (
github.com/PuerkitoBio/goquery v1.9.2
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/anchore/bubbly v0.0.0-20230518153401-87b6af8ccf22
github.com/anchore/clio v0.0.0-20230802135737-4778c80552e5
github.com/anchore/fangs v0.0.0-20230628163043-a51c5a39b097
github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a
github.com/anchore/bubbly v0.0.0-20241107060245-f2a5536f366a
github.com/anchore/clio v0.0.0-20241029130133-ceccbddab86f
github.com/anchore/fangs v0.0.0-20241031222233-81506aed5251
github.com/anchore/go-logger v0.0.0-20241005132348-65b4486fbb28
github.com/anchore/go-macholibre v0.0.0-20220308212642-53e6d0aaf6fb
github.com/aws/aws-sdk-go v1.55.5
github.com/blacktop/go-macho v1.1.231
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/lipgloss v0.12.1
github.com/charmbracelet/bubbletea v1.2.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/gabriel-vasile/mimetype v1.4.5
github.com/github/smimesign v0.2.0
github.com/go-restruct/restruct v1.2.0-alpha
Expand All @@ -31,39 +31,38 @@ require (
)

require (
github.com/adrg/xdg v0.4.0 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/adrg/xdg v0.5.3 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blacktop/go-dwarf v1.0.10 // indirect
github.com/charmbracelet/bubbles v0.11.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
github.com/charmbracelet/x/input v0.1.0 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/charmbracelet/x/ansi v0.4.5 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/erikgeiser/promptkit v0.7.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gkampitakis/go-snaps v0.4.5 // indirect
github.com/erikgeiser/promptkit v0.9.0 // indirect
github.com/felixge/fgprof v0.9.5 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/google/pprof v0.0.0-20241101162523-b92577c0c142 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-localereader v0.0.2-0.20220822084749-2491eb6c1c75 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -73,27 +72,30 @@ require (
github.com/muesli/termenv v0.15.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pborman/indent v1.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 722f43a

Please sign in to comment.