diff --git a/pkg/cmd/alias/list/list.go b/pkg/cmd/alias/list/list.go index 1039759e3..2f17ed195 100644 --- a/pkg/cmd/alias/list/list.go +++ b/pkg/cmd/alias/list/list.go @@ -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) } diff --git a/pkg/cmd/alias/list/list_test.go b/pkg/cmd/alias/list/list_test.go index 59b7ed0ef..2f8af41cd 100644 --- a/pkg/cmd/alias/list/list_test.go +++ b/pkg/cmd/alias/list/list_test.go @@ -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: "", }, }