Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add examples to cmd help
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed May 9, 2023
1 parent 191b417 commit de4e7cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
2 changes: 2 additions & 0 deletions pkg/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,5 @@ func regionsCompletion(ctx context.Context, c client.Client, toComplete string)

return result, nil
}

// TODO(njhale): Add completions for Event filter arguments
64 changes: 46 additions & 18 deletions pkg/cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,57 @@ import (

func NewEvent(c CommandContext) *cobra.Command {
cmd := cli.Command(&Events{client: c.ClientFactory}, cobra.Command{
Use: "events [flags]",
// TODO(njhale): Add examples
Example: `
# List Acorn events.
`,
Use: "events [flags] FILTER",
SilenceUsage: true,
Short: "List Acorn events",
// TODO(njhale): better long description
Long: "List events about Acorn resources",
// Args: cobra.MinimumNArgs(1),
})
// cmd.Flags().SetInterspersed(false)
Short: "List events about Acorn resources",
Args: cobra.MaximumNArgs(1),
// ValidArgsFunction: newCompletion(c.ClientFactory, imagesCompletion(true)).withSuccessDirective(cobra.ShellCompDirectiveDefault).withShouldCompleteOptions(onlyNumArgs(1)).complete,
Example: `# List all events in the current project
acorn events
# List events across all projects
acorn -A events
# Stream events in the current project
acorn events -w
# List the last 10 events
acorn events --tail 10
# Filtering by Resource
# The FILTER argument comes in the form '<kind>/<name>' and, when given, prunes the result set to contain events related to Acorn resources with the respective kind and name.
# List events related to the 'hello' app in the current project
acorn events app/hello
# The '/<name>' suffix is optional and, when omitted, matches events related to any resource of the given kind.
# List events related to any volume in the current project
acorn events vol
# Filtering by Time
# The --since and --until options can be Unix timestamps, date formatted timestamps, or Go duration strings (relative to system time).
# List events observed within the last 15 minutes
acorn events --since 15m
# List events observed between 2023-05-08T15:04:05 and 2023-05-08T15:05:05 (inclusive)
acorn events --since '2023-05-08T15:04:05' --until '2023-05-08T15:05:05'
# Getting Event Context
# The 'context' field provides additional information about an event.
# By default, this field is elided from this command's output, but can be enabled via the '--with-context' field.
acorn events --with-context
`})
return cmd
}

type Events struct {
// TODO(njhale): Fix flags/options
Filter string `usage:"Filter output based on conditions provided" short:"f"`
Since *time.Duration `usage:"Show all events created since timestamp" short:"s"`
Until *time.Duration `usage:"Stream events until this timestamp" short:"u"`
Quiet bool `usage:"Output only names" short:"q"`
Output string `usage:"Output format (json, yaml, {{gotemplate}})" short:"o"`
client ClientFactory
Since *time.Duration `usage:"Show all events created since timestamp" short:"s"`
Until *time.Duration `usage:"Stream events until this timestamp" short:"u"`
WithContext bool `usage:"Don't strip the event context from response" short:"c"`
Watch bool `usage:"Stream events" short:"w"`
Tail *int `usage:"Return this number of latest events" short:"t"`
Output string `usage:"Output format (json, yaml, {{gotemplate}})" short:"o"`
client ClientFactory
}

func (e *Events) Run(cmd *cobra.Command, args []string) error {
Expand All @@ -49,7 +77,7 @@ func (e *Events) Run(cmd *cobra.Command, args []string) error {
}

// TODO(njhale): Implement filters, watch, etc
out := table.NewWriter(tables.Event, e.Quiet, e.Output)
out := table.NewWriter(tables.Event, false, e.Output)
events, err := c.EventList(cmd.Context())
if err != nil {
out.Write(err)
Expand Down

0 comments on commit de4e7cc

Please sign in to comment.