Commit Graph

42 Commits

Author SHA1 Message Date
tomerf
5deb57bbca Fixed completion of dash parameters arguments (#415) 2017-04-08 10:45:37 -04:00
Tamir Duberstein
7aeaa2cce6 Avoid storing pointer to nil (#411)
* Fix shellcheck

Before this change:

	In - line 204:
	    declare -F $next_command >/dev/null && $next_command
	               ^-- SC2086: Double quote to prevent globbing and word splitting.

	--- FAIL: TestBashCompletions (0.34s)
		bash_completions_test.go:138: shellcheck failed: exit status 1

* Avoid storing pointer to nil

Before this change, the new test fails with:

	--- FAIL: TestSetOutput (0.00s)
		command_test.go:198: expected setting output to nil to revert back to stdout, got <nil>
2017-04-02 10:14:34 -04:00
Vincent Batts
c29ece4386 Go vet (#345)
* bash_completions: cleanup for go vet

The gnarly block of string in the Fprint tripped up go vet and was not
easy to read.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>

* test: cleanup for go vet

Looks like copy'pasta and an unused variable

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-01-26 14:32:19 -05:00
Oleg Atamanenko
0f056af21f Added godocs to public methods. (#386)
* Added godocs to public methods.

* Fix gofmt formatting.
2017-01-24 11:30:45 -05:00
bogem
71a9c0834b Simplify condition with err 2016-08-30 21:57:12 +05:00
bogem
6e17f4e2c5 Fix typos 2016-08-20 12:04:53 +05:00
Euan Kemp
40e19b3f3b Don't display deprecated flags in bash completions 2016-08-02 15:01:33 -07:00
Euan Kemp
75daccd5b8 Don't display hidden flags in bash completions 2016-08-02 14:49:33 -07:00
Eric Paris
7bf964e5b6 Do not show subcommands in bash completion if a local flag was specified
If a user specifies a flag to a command which doesn't make sense to a
subcommand do not show subcommands as a suggestion.

This also changes things to show both 'required flags' and 'commands'
instead of only 'required flags'
2016-06-03 12:44:58 -04:00
Eric Paris
ecc7ea6969 Show both commands and 'required flags' instead of only 'required flags' 2016-06-03 12:44:54 -04:00
Dr. Stefan Schimanski
defeccc04d Run shellcheck on bash completion 2016-04-02 23:16:12 +02:00
Dr. Stefan Schimanski
1a0a490d76 Remove plural handling and add aliases for nouns in completion 2016-04-02 12:39:19 +02:00
Dr. Stefan Schimanski
a23d903a12 Fix escaping of % in bash code strings 2016-03-22 17:44:59 +01:00
Dr. Stefan Schimanski
ea9a77d312 Add support for plural nouns in bash completion 2016-03-21 08:05:54 +01:00
Dr. Stefan Schimanski
8092588fb8 Add custom bash flag completion 2016-03-21 08:05:54 +01:00
Dr. Stefan Schimanski
7d556a0974 Enable bash completion after --flag= or --flag=abc 2016-03-21 08:05:49 +01:00
Anthony Fok
65a708cee0 Allow bash-completion to work with full-path executable 2016-02-08 17:06:27 -05:00
Anthony Fok
801364aa15 Skip "bash: declare: -A: invalid option" error gracefully
The use of "declare -A flaghash" (associative array) was introduced
in PR #205, which works perfectly for Bash 4.x, but OS X insists on
shipping a very outdated Bash 3.2.x.

This patch hides the "bash: declare: -A: invalid option" error message
and allows the bash completion script to continue gracefully on
OS X, albeit without the benefit of the new feature in PR #205.

Fixes #240
2016-02-05 13:04:36 +08:00
Anthony Fok
97f831a4fd Change first line of generated bash-completion file
to conform with existing bash-completion snippets and
to suppress Lintian "script-not-executable".
2016-01-11 15:37:32 -07:00
Daniel Martí
e0479ff7a7 Add error handling to GenBashCompletion
Since the switch from *bytes.Buffer to io.Writer, errors can no longer
be ignored. Also makes the reuse of GenBashCompletion in
GenBashCompletionFile without a buffer treat errors properly again.
2016-01-05 21:31:19 +01:00
Daniel Martí
a5ff2f28ab Reuse GenBashCompletion in GenBashCompletionFile 2016-01-05 21:30:42 +01:00
Daniel Martí
463be1428d Replace *bytes.Buffer with io.Writer
Also adds support for generating bash completions on writers other than
just buffers.

Found via github.com/mvdan/interfacer.
2016-01-05 21:30:42 +01:00
Tamer TAS
c6399cd398 Use readline's default filename completion if completion fails
If the `compspec` generates no matches it uses bash filename completion instead.
2016-01-02 08:11:35 +02:00
Kenjiro Nakayama
60b8213eba Add flaghash to bash_completion to keep flag value 2015-12-24 08:53:30 -05:00
Adam Bozanich
fe79245d1a Bash completion for names with ':' character. 2015-12-09 20:57:45 -08:00
Anthony Fok
0e4c02d9cb Restore bash completion behaviour for bash 4.x
In Pull Request #178, the use of `builtin compopt` as a test condition
is inappropriate.  Use `[[ $(type -t compopt) = "builtin" ]]` instead.

Also clean up formatting of the resulting bash completion script.
2015-11-07 04:39:28 -07:00
Fabiano Franz
7290a944e4 Allow marking persistent flags as required or filename 2015-11-06 08:43:09 -05:00
Fabiano Franz
dab963a797 Persistent flags should also be used in completions 2015-11-06 08:43:09 -05:00
Eric Paris
2e6a428921 Merge pull request #179 from eparis/init_comp
Check for _init_completion not_init_completionS
2015-11-03 15:41:40 -05:00
Matt McCoy
428babeb31 Modifying bash completions so they can run on OSX 2015-11-03 15:21:24 -05:00
Eric Paris
58e38f95da Check for _init_completion not_init_completionS 2015-11-03 15:09:37 -05:00
Eric Paris
3eac1434ef Update IsAvailableCommand checks
This slightly changes IsAvailableCommand in that a non-runnable command
with a runnable subcommand is now 'Available'

We also use IsAvailableCommand in the rest of the codebase instead of
half kinda sorta doing it incorrectly other places.
2015-09-08 22:48:12 -04:00
Eric Paris
32e87e3c8e Enable bash completions on Macs
If they installed bash-completions from homebrew, this should make our
completions work.
2015-09-03 17:00:18 -04:00
Eric Paris
9e7788657f Auto generation of a man page 2015-08-21 01:10:13 -07:00
Anthony Fok
1e6fdf608f Add new BashCompSubdirsInDir annotation
This first `cd` to a specified directory, then
lists the subdirectories therein with `_filedir -d`.

This can be used by e.g. `hugo --theme=[Tab][Tab]`, which would
give a list of subdirectories under the `themes` directory.
2015-08-09 13:30:58 -06:00
Jordan Liggitt
6119fc993e Simplify setting file/extension annotations on a flag 2015-06-22 15:16:00 -04:00
Eric Paris
dff410ab56 make filename extension handling a bash function
We were trying to call a bash function with bash stuff like @ () from a
variable.  Stop that.  Just call a function with an arg from a variable
instead of trying to pass around the bash.

Should fix https://github.com/spf13/cobra/pull/103
2015-05-04 18:41:53 -04:00
Eric Paris
f4b3401f9e Clean up minor bash complaints from shellcheck.net 2015-05-04 14:40:27 -04:00
Eric Paris
c3e48f996d Deprecated subcommands
They should still work, but shouldn't show up in help or usage output
2015-04-29 13:08:20 -04:00
Eric Paris
0fc734c3c5 Sort the valid args before output
We do this so we get stable repeatable output and can see if updates are
necessary or if it is just golang doing the same thing twice differently
2015-04-13 18:44:05 -04:00
Eric Paris
a068307565 add a helper to annotate a flag as 'required' by a command 2015-04-07 20:14:18 -04:00
Eric Paris
9b2e6822e5 Add bash autocompletion generator
Given a (potentially annotated) cobra command you can generate a bash
completion script.
2015-04-07 20:13:49 -04:00