Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bash shell completion command #3084

Merged
merged 3 commits into from Mar 11, 2019

Conversation

@srfrog
Copy link
Contributor

commented Mar 1, 2019

This PR adds a new completion command to the Dgraph main binary. It is used to generate bash and zsh shell completion code.

Bash example:

$ dgraph completion bash > dgraph.sh

# source in .bashrc
source dgraph.sh

This change is Reviewable

@srfrog srfrog requested a review from dgraph-io/team Mar 1, 2019
. < (dgraph completion)
`,
Run: func(cmd *cobra.Command, args []string) {
RootCmd.GenBashCompletion(os.Stdout)

This comment has been minimized.

Copy link
@golangcibot

golangcibot Mar 1, 2019

Error return value of RootCmd.GenBashCompletion is not checked (from errcheck)

@danielmai

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

Tried it out. It seems pretty useful. Here's what it like it action (<TAB> means I pressed the tab key):

$ dgraph <TAB><TAB>
acl              bash-completion  cert             debug            live             version          
alpha            bulk             conv             increment        restore          zero             
$ dgraph alpha -<TAB><TAB>
--acl_access_ttl=      --badger.vlog=         --expand_edge          --log_dir=             -p                     --tls_dir=             --wal=
--acl_cache_ttl=       --bindall              --export=              --logtostderr          --pending_proposals=   --tls_use_system_ca    --whitelist=
--acl_refresh_ttl=     --block_rate=          --expose_trace         --lru_mb=              --port_offset=         --trace=               -z
--acl_secret_file=     --config=              --idx=                 --max_retries=         --postings=            -v                     --zero=
--alsologtostderr      --custom_tokenizers=   --jaeger.collector=    --mutations=           --profile_mode=        --v=                   
--auth_token=          --debugmode            -l                     --my=                  --query_edge_limit=    --vmodule=             
--badger.tables=       --enterprise_features  --log_backtrace_at=    -o                     --tls_client_auth=     -w       
dgraph completion command with two subcommands for bash and zsh.
@danielmai

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

Zsh completion isn't working for me.

$ ./dgraph completion zsh
#compdef dgraph

_arguments \
  '1: :->level1' \
  '2: :->level2' \
  '3: :_files'
case $state in
  level1)
    case $words[1] in
      dgraph)
        _arguments '1: :(acl alpha bulk cert completion conv debug help increment live restore version zero)'
      ;;
      *)
        _arguments '*: :_files'
      ;;
    esac
  ;;
  level2)
    case $words[2] in
      acl)
        _arguments '2: :(chmod groupadd groupdel info passwd useradd userdel usermod)'
      ;;
      cert)
        _arguments '2: :(ls)'
      ;;
      completion)
        _arguments '2: :(bash zsh)'
      ;;
      *)
        _arguments '*: :_files'
      ;;
    esac
  ;;
  *)
    _arguments '*: :_files'
  ;;
esac
$ source <(./dgraph completion zsh)
_arguments:comparguments:319: can only be called from completion function
_arguments:comparguments:319: can only be called from completion function
Copy link
Contributor

left a comment

I agree that shell completion would be helpful but I'm not sure that it should be a core dgraph command. The output is fixed for a given dgraph release. The same could be accomplished by just adding static completion files to the release package.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @srfrog)

Copy link
Member

left a comment

:lgtm: This is useful. Either the user or our install scripts can use this to set up auto-completion based on whichever version dgraph is.

Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @srfrog)

Copy link
Contributor Author

left a comment

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @golangcibot)


dgraph/cmd/root.go, line 167 at r1 (raw file):

Previously, golangcibot (Bot from GolangCI) wrote…

Error return value of RootCmd.GenBashCompletion is not checked (from errcheck)

Done.

@srfrog srfrog marked this pull request as ready for review Mar 11, 2019
@srfrog srfrog merged commit 9bb6909 into master Mar 11, 2019
3 of 5 checks passed
3 of 5 checks passed
CI (dgraph) TeamCity build failed
Details
code-review/reviewable 1 discussion left (golangcibot)
Details
GolangCI No issues found!
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details
@srfrog srfrog deleted the srfrog/issue-3083_autocomplete_dgraph_tools branch Mar 11, 2019
dna2github added a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
* dgraph/cmd/root.go: add bash shell completion command

* dgraph/cmd/root.go: add zsh shell completion

dgraph completion command with two subcommands for bash and zsh.

* dgraph/cmd/root.go: add usage instructions and help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.