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

Add completion of resource names for args and flags #102

Closed
wants to merge 10 commits into from

Conversation

ericbottard
Copy link
Contributor

Fixes #74

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO in server

Copy link
Member

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"?

@ericbottard ericbottard added this to the v0.5.0 milestone Oct 21, 2019
@codecov
Copy link

codecov bot commented Oct 21, 2019

Codecov Report

Merging #102 into master will increase coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pkg/build/commands/credential_apply.go 98.41% <100%> (ø) ⬆️
pkg/streaming/commands/processor_create.go 100% <100%> (ø) ⬆️
pkg/knative/commands/adapter_create.go 99.37% <100%> (+0.02%) ⬆️
pkg/riff/commands/completion.go 99.45% <100%> (+2.09%) ⬆️
pkg/cli/flags.go 100% <100%> (ø) ⬆️
pkg/build/commands/application_create.go 96.98% <100%> (+0.01%) ⬆️
pkg/core/commands/deployer_create.go 98.36% <100%> (+0.02%) ⬆️
pkg/build/commands/function_create.go 96.92% <100%> (+0.01%) ⬆️
pkg/riff/commands/root.go 95.71% <100%> (+0.19%) ⬆️
pkg/streaming/commands/stream_create.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7ad872...da1bad0. Read the comment docs.

Copy link
Member

@scothis scothis left a 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))
Copy link
Member

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))
Copy link
Member

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))
Copy link
Member

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

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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 }}"
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
template="{{ range .items }}{{ .metadata.name }} {{ end }}"
template="{{ range .items }}{{ .metadata.name }} {{ end }}"

Copy link
Contributor Author

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 }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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}'))
Copy link
Member

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
Copy link
Member

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))
Copy link
Member

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

Copy link
Contributor Author

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...

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just vanilla GoLand which highlights constructs like these. It's pretty effective, but also noisy in these cases:

Screen Shot 2019-10-21 at 18 18 55

Copy link
Member

@scothis scothis left a 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.

@ericbottard
Copy link
Contributor Author

Merged as e92ef2d

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource name shell completion
2 participants