Support standard output format flags for secret and deploy-key list by rajhawaldar · Pull Request #8081 · cli/cli · GitHub
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
6 changes: 3 additions & 3 deletions pkg/cmd/repo/deploy-key/list/http.go
15 changes: 14 additions & 1 deletion pkg/cmd/repo/deploy-key/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ type ListOptions struct {
IO *iostreams.IOStreams
HTTPClient func() (*http.Client, error)
BaseRepo func() (ghrepo.Interface, error)
Exporter cmdutil.Exporter
}

var deployKeyFields = []string{
"id",
"key",
"title",
"createdAt",
"readOnly",
}

func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
Expand All @@ -40,7 +49,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
return listRun(opts)
},
}

cmdutil.AddJSONFlags(cmd, &opts.Exporter, deployKeyFields)
return cmd
}

Expand All @@ -64,6 +73,10 @@ func listRun(opts *ListOptions) error {
return cmdutil.NewNoResultsError(fmt.Sprintf("no deploy keys found in %s", ghrepo.FullName(repo)))
}

if opts.Exporter != nil {
return opts.Exporter.Write(opts.IO, deployKeys)
}

//nolint:staticcheck // SA1019: utils.NewTablePrinter is deprecated: use internal/tableprinter
t := utils.NewTablePrinter(opts.IO)
cs := opts.IO.ColorScheme()
Expand Down
25 changes: 19 additions & 6 deletions pkg/cmd/secret/list/list.go