* Make preamble functions unique to command
Prior to this commit the functions in the preamble had names that didn't
vary based on the command for which the bash completion was generated.
This meant that if you had two bash completions with differences in the
preamble functions then only the last loaded function would be
available.
This commit prefixes all of these functions with the name of the command
so that multiple cobra generated completion files won't clash.
Signed-off-by: John McCabe <john@johnmccabe.net>
* Fix function names in writeFlagHandler
The references to the `__handle_filename_extension_flag` and
`__handle_subdirs_in_dir_flag` functions in `writeFlagHandler` hadn't
been updated correctly in the previous commits.
Signed-off-by: John McCabe <john@johnmccabe.net>
* Pass cmd into writeFlagHandler
This commit passes the cmd pointer into the writeFlagHandler so that the
`__handle_filename_extension_flag` and `__handle_subdirs_in_dir_flag`
functions can have the `cmd.Name()` prefixed.
* Update Bash completion tests
Prefixes the tested `__handle_filename_extension_flag` and
`__handle_subdirs_in_dir_flag` functions with the command name.
Trivial addition to the first example in `README.md` that defines the
`cmd.Execute()` function that is referenced further down in the `main.go`
example.
* Add `CalledAs` method to Command (w/ tests)
The `CalledAs` method returns the name of the command or alias that
invoked the command -- as long as the command was actually invoked.
Otherwise, it returns the empty string.
The opens up possibilies for commands to behave differently based on
which alias invoked the command (in the same vein as Linux programs
which adjust their behavior based on the value of argv[0]).
* Fixed formatting
* Fix attemptd assignment to non-variable in bash 3
flaghash variable is an associative array which is only supported in
bash > 3.
* Use -gt instead of >
Make it so that, in the case that the root command is not runnable
but has subcommands, specifying a '--version' flag will still
run the "version" behavior.
Update Cobra generator to make rootCmd private rather than
exporting it. Also update examples in README to use the exported
Execute() command rather than referencing unexported rootCmd.
Fixes#556