fix: lazysecrets list puts the name first, and keeps errors out of fzf
This commit is contained in:
3 files changed
+35
-18
No files matched your search
+15
-7
@@ -25,23 +25,31 @@ import (
|
||||
// listCmd prints every source, vault and secret lazysecrets can find, one
|
||||
// per line, for fzf, editor pickers and scripts:
|
||||
//
|
||||
// lazysecrets list | fzf --ansi --delimiter='\t' --with-nth=3 | cut -f1
|
||||
// lazysecrets list | fzf --ansi --delimiter='\t' --with-nth=1 | cut -f2
|
||||
//
|
||||
// The name is coloured from the theme, with the provider's icon (as in
|
||||
// the TUI: --icons, LAZYSECRETS_ICONS, ui.icons); the link never is.
|
||||
// Each line is the name, then the link: the name coloured from the theme,
|
||||
// with the provider's icon (as in the TUI: --icons, LAZYSECRETS_ICONS,
|
||||
// ui.icons); the link never is.
|
||||
//
|
||||
// What's cached prints at once; what's missing or older than --max-age
|
||||
// follows as it loads. Lists that can't be read are reported on stderr.
|
||||
func listCmd(providers []provider.Provider, cachePath string, timeout func(provider.Kind) time.Duration, theme styles.Styles, withIcons bool, args []string, out, errOut io.Writer) error {
|
||||
// follows as it loads. Lists that can't be read are reported to errOut:
|
||||
// stderr when the output is on the terminal, nothing when it goes into
|
||||
// fzf, whose screen they'd draw over; --errors reports them to stderr
|
||||
// either way.
|
||||
func listCmd(providers []provider.Provider, cachePath string, timeout func(provider.Kind) time.Duration, theme styles.Styles, withIcons bool, args []string, out, errOut, stderr io.Writer) error {
|
||||
fs := flag.NewFlagSet("list", flag.ContinueOnError)
|
||||
cached := fs.Bool("cached", false, "only what's cached, and repos: load nothing from Azure or Databricks")
|
||||
maxAge := fs.Duration("max-age", 2*time.Minute, "load cached lists older than this again")
|
||||
format := fs.String("format", "text", "text: link, kind and name, tab-separated; json: an object per line")
|
||||
format := fs.String("format", "text", "text: name and link, tab-separated; json: an object per line")
|
||||
color := fs.String("color", "always", "colour the names (text): always or never; fzf needs --ansi")
|
||||
iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)")
|
||||
showErrors := fs.Bool("errors", false, "report lists that can't be read on stderr also when the output goes into a pipe")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if *showErrors {
|
||||
errOut = stderr
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
return fmt.Errorf("usage: lazysecrets list [--cached] [--max-age 2m] [--format text|json]")
|
||||
}
|
||||
@@ -56,7 +64,7 @@ func listCmd(providers []provider.Provider, cachePath string, timeout func(provi
|
||||
switch *format {
|
||||
case "text":
|
||||
write = func(e listing.Entry) error {
|
||||
_, err := fmt.Fprintf(out, "%s\t%s\t%s\n", e.Link, e.Kind, nameOf(e, theme, iconSet, *color == "always"))
|
||||
_, err := fmt.Fprintf(out, "%s\t%s\n", nameOf(e, theme, iconSet, *color == "always"), e.Link)
|
||||
return err
|
||||
}
|
||||
case "json":
|
||||
|
||||
Reference in new issue
Block a user