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

Initial autocompletion #3412

Merged
merged 2 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func realMain() int {
}

cli := &cli.CLI{
Args: args,
Commands: command.Commands,
HelpFunc: cli.FilteredHelpFunc(cmds, cli.BasicHelpFunc("consul")),
Args: args,
Commands: command.Commands,
Autocomplete: true,
Name: "consul",
HelpFunc: cli.FilteredHelpFunc(cmds, cli.BasicHelpFunc("consul")),
}

exitCode, err := cli.Run()
Expand Down
17 changes: 17 additions & 0 deletions website/source/docs/commands/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ Command Options
Joins a server to another server in the WAN pool.
```

## Autocompletion

The `consul` command features opt-in subcommand autocompletion that you can
enable for your shell with `consul -autocomplete-install`. After doing so,
you can invoke a new shell and use the feature.

For example, assume a tab is typed at the end of each prompt line:

```
$ consul e
event exec

$ consul r
raft reload rtt
Copy link
Contributor

Choose a reason for hiding this comment

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

raft is actually a subcommand of operator which looks like a limitation of the autocomplete library.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I noticed that it doesn't do sub-sub commands

Copy link
Contributor

@preetapan preetapan Oct 6, 2017

Choose a reason for hiding this comment

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

I tried this out just now and it worked on sub subcommands too, this is pretty cool.

preetha@preetha-work ~/go/src/github.com/hashicorp/consul-oss (jbs-autocomplete) $consul r
reload  rtt     
preetha@preetha-work ~/go/src/github.com/hashicorp/consul-oss (jbs-autocomplete) $consul r
reload  rtt     
preetha@preetha-work ~/go/src/github.com/hashicorp/consul-oss (jbs-autocomplete) $consul operator 
autopilot  raft       
preetha@preetha-work ~/go/src/github.com/hashicorp/consul-oss (jbs-autocomplete) $consul operator raft 
list-peers   remove-peer  

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll update the documentation and then merge this. this is ready to go


```

## Environment Variables

In addition to CLI flags, Consul reads environment variables for behavior
Expand Down