Change alias list output format to YAML (#6603)
Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
parent
6f1d149da3
commit
e86b3ea91f
2 changed files with 18 additions and 19 deletions
|
|
@ -1,14 +1,12 @@
|
|||
package list
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/cli/cli/v2/internal/config"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/cli/cli/v2/pkg/iostreams"
|
||||
"github.com/cli/cli/v2/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ListOptions struct {
|
||||
|
|
@ -50,23 +48,11 @@ func listRun(opts *ListOptions) error {
|
|||
aliasCfg := cfg.Aliases()
|
||||
|
||||
aliasMap := aliasCfg.All()
|
||||
|
||||
if len(aliasMap) == 0 {
|
||||
return cmdutil.NewNoResultsError("no aliases configured")
|
||||
}
|
||||
|
||||
//nolint:staticcheck // SA1019: utils.NewTablePrinter is deprecated: use internal/tableprinter
|
||||
tp := utils.NewTablePrinter(opts.IO)
|
||||
keys := []string{}
|
||||
for alias := range aliasMap {
|
||||
keys = append(keys, alias)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, alias := range keys {
|
||||
tp.AddField(alias+":", nil, nil)
|
||||
tp.AddField(aliasMap[alias], nil, nil)
|
||||
tp.EndRow()
|
||||
}
|
||||
|
||||
return tp.Render()
|
||||
enc := yaml.NewEncoder(opts.IO.Out)
|
||||
return enc.Encode(aliasMap)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,20 @@ func TestAliasList(t *testing.T) {
|
|||
gc: "!gh gist create \"$@\" | pbcopy"
|
||||
`),
|
||||
isTTY: true,
|
||||
wantStdout: "co: pr checkout\ngc: !gh gist create \"$@\" | pbcopy\n",
|
||||
wantStdout: "co: pr checkout\ngc: '!gh gist create \"$@\" | pbcopy'\n",
|
||||
wantStderr: "",
|
||||
},
|
||||
{
|
||||
name: "multiline",
|
||||
config: heredoc.Doc(`
|
||||
aliases:
|
||||
one: "foo\nbar\n"
|
||||
two: |-
|
||||
!chicken
|
||||
coop
|
||||
`),
|
||||
isTTY: true,
|
||||
wantStdout: "one: |\n foo\n bar\ntwo: |-\n !chicken\n coop\n",
|
||||
wantStderr: "",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue