Skip to content

Commit

Permalink
feat: add --name-only flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rbjorklin committed May 29, 2024
1 parent 81033e4 commit e42b51d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ksort.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type options struct {

filenameOptions resource.FilenameOptions
delete bool
nameOnly bool

genericclioptions.IOStreams
}
Expand Down Expand Up @@ -106,6 +107,8 @@ func NewCommand(streams genericclioptions.IOStreams) *cobra.Command {

o.filenameFlags.AddFlags(cmd.Flags())
cmd.Flags().BoolVarP(&o.delete, "delete", "d", o.delete, "Sort manifests in uninstall order")
cmd.Flags().
BoolVarP(&o.nameOnly, "name-only", "n", o.nameOnly, "Print only the name of the sorted manifests")
cmd.Flags().BoolVar(&printVersion, "version", printVersion, "Print the version and exit")
cmd.Flags().AddGoFlagSet(flag.CommandLine)

Expand Down Expand Up @@ -172,7 +175,6 @@ func (o *options) run() error {

return nil
})

if err != nil {
return err
}
Expand Down Expand Up @@ -228,7 +230,13 @@ func (o *options) run() error {
a[i] += m.Content
}

fmt.Fprintln(o.Out, strings.Join(a, "\n---\n"))
if o.nameOnly {
for _, m := range sortManifestsByKind(manifests, sortOrder) {
fmt.Println(m.Name)
}
} else {
fmt.Fprintln(o.Out, strings.Join(a, "\n---\n"))
}

return nil
}

0 comments on commit e42b51d

Please sign in to comment.