Commit graph

1024 commits

Author SHA1 Message Date
Yash Ladha
f25a3c6e0b
fix: conflict import name with variable (#1879)
`template` is an import in `cobra.go` file and also used as a variable
name, which masks the library in the scope of that function.
2022-12-15 05:39:50 -05:00
Unai Martinez-Corral
923592041e
ci: deprecate go 1.15 (#1866)
Remove testing for go 1.15 to allow CI to pass, but don't force projects to upgrade.
2022-12-09 16:57:19 -05:00
David Wertenteil
a6f198b635
Update kubescape org (#1874)
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2022-12-06 08:20:58 -05:00
dependabot[bot]
7bb1440003
build(deps): bump golangci/golangci-lint-action from 3.2.0 to 3.3.1 (#1851)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.2.0 to 3.3.1.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.2.0...v3.3.1)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-26 08:18:05 -05:00
Unai Martinez-Corral
6200c8e551
Makefile: add target richtest (#1865)
Don't require contributors to install richgo but keep it as an option and for CI
2022-11-25 15:55:09 -05:00
Norman Dankert
c6b9971923
fix: force ForEach-Object to return array in pwsh completion (#1850)
Fixes #1847
2022-11-25 15:47:20 -05:00
Enrico Candino
430549841b
Update stale.yml (#1863) 2022-11-21 21:04:26 -05:00
Brian Pursley
ad6db7f8f6
Create unit test illustrating unknown flag bug (#1854)
Created a unit test that tests the unknown flag
error message when the unknown flag is located
in different arg positions.
2022-11-14 21:46:57 -05:00
Brian Pursley
6b0bd3076c
fix: don't remove flag value that matches subcommand name (#1781)
When the command searches args to find the arg matching a
particular subcommand name, it needs to ignore flag values,
as it is possible that the value for a flag might match
the name of the sub command.

This change improves argsMinusFirstX() to ignore flag values
when it searches for the X to exclude from the result.
2022-11-07 23:12:02 -05:00
mike76-dev
cc7e235fc2
Add Sia to projects using Cobra (#1844) 2022-11-01 09:15:28 -04:00
Marc Khouzam
10cf7be997
Check for group presence after full initialization (#1839)
Fixes #1831

By moving the check for help group existence to "ExecuteC()" we no
longer need groups to be added before AddCommand() is called.  This
provides more flexibility to developers and works better with the use
of "init()" for command creation.

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-10-24 11:11:57 -04:00
doniacld
4b9d00dfec
Replace deprecated ExactValidArgs with MatchAll in user_guide and shell_completions example (#1836) 2022-10-20 16:33:37 -04:00
Ville Skyttä
badcce14f8
style(bash-v2): various cleanups (#1702)
* use arithmetic evaluation in numeric context

* remove unnecessary $ from array index variables

* [[ ]] over [ ], == over =, remove unnecessary quoting

* use ${foo-} rather than ${foo:-} in emptiness check

The result of the expansion is null no matter if the variable is unset
or null in both cases; the former form is arguably easier on the eye.

* remove unnecessary trailing linefeed removal

No longer needed as of f464d6c82e, saves
a subshell.

* use herestring in activehelp extraction

Herestrings read cleaner than process substitutions, and work in posix
mode (but we do and will have some process substitutions so this doesn't
matter much). Both approaches may end up using temporary files.
2022-10-17 15:24:27 -04:00
Fabian Kammel
1424b7b927
Add Constellation to projects using cobra. (#1829) 2022-10-13 09:47:58 -04:00
Gustavo Bazan
860791844e
feat: make InitDefaultCompletionCmd public (#1467)
* feat: make InitDefaultCompletionCmd public

* PR comments

* Update man_docs_test.go

* Update README.md
2022-10-10 19:06:30 -04:00
aawsome
2169adb574
Add groups for commands in help (#1003)
* Add tests for grouping commands
* Adds Additional Command section in help

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-10-10 14:59:11 -06:00
Marc Khouzam
212ea40783
Include --help and --version flag in completion (#1813)
Fixes #1786

The --help, -h, --version and -v flags are normally added when the
`execute()` function is called on a command.  When doing completion
we don't call `execute()` so we need to add these flags explicitly to
the command being completed.

Also, we disable all further completions if the 'help' or 'version'
flags are present on the command-line.

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-10-04 16:41:30 -06:00
Marc Khouzam
d4040ad8db
Allow user to add completion for powershell alias (#1621)
When a user has an alias in powershell, she will need to register that
alias for completion.  To make that possible, we store the completion
logic into a scriptblock variable which can easily be accessed by the
user to register aliases.

For example, if the user defines an alias for `helm`:
   PS> sal h helm
she will need to register the alias like so:
   PS> Register-ArgumentCompleter -CommandName 'h' -ScriptBlock $__helmCompleterBlock

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2022-10-03 13:06:04 -04:00
Varun Sharma
23fc5e099f
ci: add minimum GitHub token permissions for workflows (#1792)
Signed-off-by: Varun Sharma <varunsh@stepsecurity.io>
2022-10-03 08:53:12 -06:00
Yann Soubeyrand
93d1913fb0
Add OnFinalize method (#1788)
This method is the OnInitialize counterpart. Like OnInitialize which allows
loading the configuration before each command is executed, OnFinalize allows
saving the configuration after each command has been executed.
2022-10-03 08:52:50 -06:00
dependabot[bot]
07034fee49
build(deps): bump actions/stale from 5 to 6 (#1815)
Bumps [actions/stale](https://github.com/actions/stale) from 5 to 6.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-03 08:52:25 -06:00
Dima Brusilovsky
3dc9761b36
Add allero to list of projects using cobra (#1819) 2022-10-03 08:52:01 -06:00
Francis Nickels III
7039e1fa21
Add '--version' flag to Help output (#1707) 2022-09-30 14:26:05 -04:00
Skeet WU
fce8d8aeb0
Expose ValidateRequiredFlags and ValidateFlagGroups (#1760) 2022-09-27 06:27:48 -04:00
Marc Khouzam
a281c8b47b
Document option to hide the default completion cmd (#1779)
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-09-16 14:44:28 -06:00
Unai Martinez-Corral
459fc5fce3
ci: add workflow_dispatch (#1387) 2022-09-16 16:23:19 -04:00
Unai Martinez-Corral
6d978a911e
add missing license headers (#1809) 2022-09-16 07:55:56 -04:00
Unai Martinez-Corral
4065a33bfd
ci: use action/setup-go's cache (#1783)
* ci: use action/setup-go's cache
* ci: deprecate Golang 1.14
2022-09-13 21:31:59 -06:00
Marc Khouzam
7e289f46f1
Adjustments to documentation (#1656)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2022-09-11 17:48:42 -04:00
Marc Khouzam
fe08012edd
Rename Powershell completion tests (#1803)
The name of the powershell completion test file did not match
the actual powershell file.

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-09-11 15:04:53 -06:00
Yuval Goldberg
d689184a42
Support for case-insensitive command names (#1802)
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves #1382
2022-09-11 08:25:22 -04:00
Unai Martinez-Corral
70e53f62be
Deprecate ExactValidArgs() and test combinations of args validators (#1643)
* deprecate ExactValidArgs in favour of MatchAll(OnlyValidArgs, ...)
* test combinations of args validators
* adjust docs
2022-09-10 09:33:34 -04:00
John McBride
2e8ba6f308
Use correct stale action exempt- yaml keys (#1800)
Signed-off-by: John McBride <jpmmcbride@gmail.com>
2022-09-07 18:25:01 -06:00
Marc Khouzam
0580724b5f
With go 1.18, we must use go install for a binary (#1726)
The format "go install github.com/kyoh86/richgo@latest" will work with
go 1.16 and higher.  It will not work with go 1.15.  However, since
installing "richgo" is only required for people who want to run the go
tests for the Cobra project itself, I feel it is ok to require go 1.16
or higher in this case.

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
2022-08-30 08:34:58 -06:00
Paul Meyer
2a7647ff46
Clarify SetContext documentation (#1748) 2022-08-29 22:12:56 -04:00
Unai Martinez-Corral
7045405250
ci: test on Golang 1.19 (#1782)
* ci: test on Golang 1.19

* ci: run golangci-lint on golang 1.19

* Adds `check-latest` for setup-go action v3

* ci/golangci-lint: use latest version available in setup-go's manifest

Signed-off-by: John McBride <jpmmcbride@gmail.com>
Signed-off-by: umarcor <unai.martinezcorral@ehu.eus>
Co-authored-by: John McBride <jpmmcbride@gmail.com>
2022-08-29 21:35:16 -04:00
Brian Pursley
22b617914c
fix: show flags that shadow parent persistent flag in child help (#1776)
This fixes a bug where a child flag that shadows (has the same
name as) a parent persistent flag would not be shown in the
child command's help output and the parent flag would be shown
instead under the global flags section.

This change makes the help output consistent with the
observed behavior during execution, where the child flag is
the one that is actually used.
2022-08-28 12:46:39 -04:00
Tobias Klauser
dbf85f6104
Update gopkg.in/yaml.v2 to gopkg.in/yaml.v3 (#1766)
API v3 was released in 2019 [1]. Update from the v2 API, no changes to
the packages's use needed and no breaking changes expected.

[1] https://ubuntu.com/blog/api-v3-of-the-yaml-package-for-go-is-available
2022-08-13 16:18:46 -06:00
Ville Skyttä
f911c0b89c
fix(bash-v2): activeHelp length check syntax (#1762)
```shell
$ set -u
$ foo=()
$ echo ${#foo}
bash: foo: unbound variable
echo ${#foo[*]}
0
```
The above shows that an empty array needs the suffix `[*]` when checking its length, or else it is considered unbound.
2022-08-13 17:44:47 -04:00
Zoran Regvart
7790bf97fd
fix: correct command path in see_also for YAML doc (#1771)
The `see_also` section for child commands would include only the name of
the commands. This adds the whole path, similar to how it's done for the
other documentation formats.
2022-08-13 17:31:45 -04:00
dependabot[bot]
6bf8cd8582
build(deps): bump github.com/inconshreveable/mousetrap (#1774) 2022-08-13 21:02:01 +00:00
Florian Forster
965924ac89
docs: add zitadel to the list (#1772) 2022-08-04 11:18:09 -04:00
Javier López Barba
162534f92f
doc: Add Okteto for projects using Cobra (#1759)
Signed-off-by: Javier López Barba <javier@okteto.com>
2022-07-20 16:45:07 +03:00
Ikko Ashimine
a0aadc68eb
Spelling for GitHub CLI (#1744) 2022-07-07 07:54:19 +03:00
Tobias Klauser
69083f81b2
Add Cilium to projects using Cobra (#1745) 2022-06-28 15:19:33 -06:00
Yevgeny Pats
bba9331d4e
doc: Add CloudQuery for projects using Cobra (#1742) 2022-06-25 19:17:06 +03:00
Miguel Duarte Barroso
3d38d18a23
Add KubeVirt as a project using cobra (#1741)
Reaching out on behalf of KubeVirt, an add-on for Kubernetes, enabling
users to run Virtual Machines on Kubernetes pods.

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
2022-06-23 09:36:12 -06:00
dependabot[bot]
06b06a9dc9
Bump golangci/golangci-lint-action from 3.1.0 to 3.2.0 (#1697)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.1.0...v3.2.0)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-20 20:06:17 -06:00
Marc Khouzam
5f2ec3c897
Update shell completion to respect flag groups (#1659)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Co-authored-by: Marc Khouzam <marc.khouzam@montreal.ca>
2022-06-20 20:04:28 -06:00
Paul Holzinger
b9ca5949e2
use errors.Is() to check for errors (#1730)
Since go 1.13 you can wrap errors. This make it no longer possible to
compare with `==`, instead you have to compare with `errors.Is()`.

I noticed this problem because -h was no longer working after I stared
wrapping the errors in my custom FlagErrorFunc function.
Note that this is only a problem when a custom help flag is defined.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-20 20:02:33 -06:00