-
Notifications
You must be signed in to change notification settings - Fork 12
Add completion of resource names for args and flags #102
Conversation
local template | ||
template="{{ range .items }}{{ .metadata.name }} {{ end }}" | ||
local kubectl_out | ||
if kubectl_out=$(kubectl get -o template --template="${template}" --selector streaming.projectriff.io/provisioner services 2>/dev/null); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO in server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "in server"?
Codecov Report
@@ Coverage Diff @@
## master #102 +/- ##
==========================================
+ Coverage 95.71% 95.85% +0.13%
==========================================
Files 86 86
Lines 4897 5061 +164
==========================================
+ Hits 4687 4851 +164
Misses 186 186
Partials 24 24
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's here seems to work well in the happy case, but there are a number of unaccounted for corner cases
@@ -153,6 +153,8 @@ func NewProcessorCreateCommand(ctx context.Context, c *cli.Config) *cobra.Comman | |||
|
|||
cli.NamespaceFlag(cmd, c, &opts.Namespace) | |||
cmd.Flags().StringVar(&opts.FunctionRef, cli.StripDash(cli.FunctionRefFlagName), "", "`name` of function build to deploy") | |||
_ = cmd.MarkFlagRequired(cli.StripDash(cli.FunctionRefFlagName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm. We handle required fields in the validator
@@ -110,6 +110,8 @@ func NewStreamCreateCommand(ctx context.Context, c *cli.Config) *cobra.Command { | |||
|
|||
cli.NamespaceFlag(cmd, c, &opts.Namespace) | |||
cmd.Flags().StringVar(&opts.Provider, cli.StripDash(cli.ProviderFlagName), "", "`name` of stream provider") | |||
_ = cmd.MarkFlagRequired(cli.StripDash(cli.ProviderFlagName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm. We handle required fields in the validator
@@ -102,6 +102,7 @@ func NewKafkaProviderCreateCommand(ctx context.Context, c *cli.Config) *cobra.Co | |||
|
|||
cli.NamespaceFlag(cmd, c, &opts.Namespace) | |||
cmd.Flags().StringVar(&opts.BootstrapServers, cli.StripDash(cli.BootstrapServersFlagName), "", "`address` of the kafka broker") | |||
_ = cmd.MarkFlagRequired(cli.StripDash(cli.BootstrapServersFlagName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm. We handle required fields in the validator
pkg/riff/commands/root.go
Outdated
@@ -36,6 +36,7 @@ func NewRootCommand(ctx context.Context, c *cli.Config) *cobra.Command { | |||
|
|||
cmd.Use = c.Name | |||
cmd.DisableAutoGenTag = true | |||
cmd.BashCompletionFunction = bash_completion_func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should be defined in by completion command. If we can't set the value in a PreRun, then pass the root command to NewCompletionCommand.
Going a step further. It might be nice to define the specific completion bits closer to each command group/runtime. And use a command walker to assemble all of the particular bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
The completion examples available are not particularly smart. Neither am I when it comes to bash, so...
__kubectl_get_namespaces() | ||
{ | ||
local template | ||
template="{{ range .items }}{{ .metadata.name }} {{ end }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the space before {{ end }}
intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template="{{ range .items }}{{ .metadata.name }} {{ end }}" | |
template="{{ range .items }}{{ .metadata.name }} {{ end }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pure copy pasta from the Cobra page, feel free to adjust.
__kubectl_get_streaming_provisioner_services() | ||
{ | ||
local template | ||
template="{{ range .items }}{{ .metadata.name }} {{ end }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template="{{ range .items }}{{ .metadata.name }} {{ end }}" | |
template="{{ range .items }}{{ .metadata.name }} {{ end }}" |
local template | ||
template="{{ range .items }}{{ .metadata.name }} {{ end }}" | ||
local kubectl_out | ||
if kubectl_out=$(kubectl get -o template --template="${template}" --selector streaming.projectriff.io/provisioner services 2>/dev/null); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "in server"?
__riff_debug "listing $1" | ||
local riff_output out | ||
if riff_output=$(riff $1 2>/dev/null); then | ||
out=($(echo "${riff_output}" | awk 'NR>1 {print $1}')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assumes the name will be the first column, which is not always true, but probably true enough
} | ||
|
||
__riff_custom_func() { | ||
case ${last_command} in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if someone uses an alias or the cli is built with a different name?
@@ -282,6 +282,7 @@ cluster). | |||
cmd.Flags().StringVar(&opts.Image, cli.StripDash(cli.ImageFlagName), "_", "`repository` where the built images are pushed") | |||
cmd.Flags().StringVar(&opts.CacheSize, cli.StripDash(cli.CacheSizeFlagName), "", "`size` of persistent volume to cache resources between builds") | |||
cmd.Flags().StringVar(&opts.LocalPath, cli.StripDash(cli.LocalPathFlagName), "", "path to `directory` containing source code on the local machine") | |||
_ = cmd.MarkFlagDirname(cli.StripDash(cli.LocalPathFlagName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, drop the assignment
the convention in this repo is to drop blank identifier assignments unless they are needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GoLand is pretty aggressive on the eyes for unhandled errors. I like explicit assignments that mention that we know what we're doing (at least at the time of authoring). I'm for 100% consistency though, so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which linter are you using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericbottard I addressed my main points of feedback. Back to you for approval/merge.
Merged as e92ef2d |
Fixes #74