cobra changelogs since cobra | diffwithgpt
AI Summary
The commit removes a GitHub Action workflow for labeling pull request sizes based on line count. This change likely aims to simplify the CI/CD pipeline or remove an unused tool.
Commit Log
chore: Rm GitHub Action PR size labeler (#2256)
AI Summary
The commit adds a comprehensive security policy document to the cobra project, outlining procedures for reporting vulnerabilities, response processes, disclosure policies, and best practices for users and contributors. The policy emphasizes responsible disclosure, coordinated vulnerability management, and security best practices to ensure the safety of the Go ecosystem and downstream projects.
Commit Log
feat: Add security policy (#2253)
AI Summary
The code change fixes a spelling error in the help output by correcting 'topcis' to 'topics'. This change ensures the help output is more user-friendly and consistent with standard terminology.
Commit Log
Update command.go (#2248) Fix spelling in the help output. topcis -> topics
AI Summary
The code adds context propagation to the help command to ensure it uses the correct execution context, addressing an issue where the context was not properly passed down. A new test case is introduced to verify that the help function correctly receives and uses the execution context, ensuring compatibility and correctness in context-aware command execution.
Commit Log
Flow context to command in SetHelpFunc (#2241) Fixes https://github.com/spf13/cobra/issues/2240
AI Summary
The commit removes a trailing curly brace from the `cobra.CompDebug` function declaration in the Markdown file. This change is likely a formatting fix to ensure consistency in the code style or to resolve a syntax issue.
Commit Log
Remove traling curlybrace (#2237)
AI Summary
The commit updates the Go version in the test workflow to 1.24. This change ensures compatibility with the latest Go features and tools.
Commit Log
Test with Go 1.24 (#2236)
AI Summary
The code reverts a change that was causing issues with test binaries by restoring the original logic for detecting test environments. The reverted logic checks if the program is running in a test environment by examining the filename, which avoids breaking unit tests that set os.Args manually.
Commit Log
Revert "Make detection for test-binary more universal (#2173)" (#2235) This reverts commit d1e9d85fcf592461f3bc2f4b6d5e140c4c0aabf8. Some programs set os.Args in their unit tests and this change would break those tests. Ref: https://github.com/spf13/cobra/pull/2173#issuecomment-2661544195
AI Summary
The code changes make `CompletionFunc` a type alias to maintain backward compatibility with existing implementations. A new test ensures that both the old and new signature formats are accepted by Cobra's completion system.
Commit Log
fix CompletionFunc implementation (#2234) The new type CompletionFunc could lead to a regression. This commit make the new `CompletionFunc` type a type alias instead, in case projects using Cobra have created their own similar type. This commit also adds a test to ensure that the completion function remains backwards-compatible.
AI Summary
The commit upgrades the pflag dependency from version 1.0.5 to 1.0.6. This change is likely to address bug fixes, security patches, or minor improvements in pflag.
Commit Log
chore: Upgrade dependencies for v1.9.0 (#2233)
AI Summary
The code change removes the default 'completion' command when a program has no sub-commands to prevent argument parsing issues. The 'InitDefaultCompletionCmd' function now checks if the 'completion' command should be created based on whether it is being called or completed.
Commit Log
Remove the default "completion" cmd if it is alone (#1559) When a program has no sub-commands, its root command can accept arguments. If we add the default "completion" command to such programs they will now have a sub-command and will no longer accept arguments. What we do instead for this special case, is only add the "completion" command if it is being called, or if it is being completed itself. We want to have the "completion" command for such programs because it will allow the completion of flags and of arguments (if provided by the program).
AI Summary
The commit updates the Cobra project's README.md to use a new logo URL from a GitHub attachment. The change replaces the local asset path with a direct link to the new logo, likely for easier access or version control.
Commit Log
New logo
AI Summary
The code introduces a new helper function CompletionWithDesc to support completion entries with descriptions, improving usability and clarity. A type alias 'Completion' is introduced to replace string in completion-related code, enhancing readability and type safety without breaking existing functionality.
Commit Log
feat: add CompletionWithDesc helper (#2231) The code has also been refactored to use a type alias for completion and a completion helper Using a type alias is a non-breaking change and it makes the code more readable and easier to understand.
AI Summary
The commit adds Conduit to the list of projects using Cobra. This update likely aims to highlight Cobra's adoption and community usage.
Commit Log
doc: add Conduit (#2230) We recently added a CLI to a our Conduit project, and we use Cobra to power it. Here's a blog post mentioning it https://meroxa.com/blog/introducing-the-new-conduit-cli:-a-powerful-tool-for-managing-your-pipelines/
AI Summary
The code allows resetting templates (usage, help, version) to their default behavior by checking if the input string is empty and setting the corresponding template field to nil. This change is a follow-up to a previous commit and enables the restoration of default templates, which was previously not possible.
Commit Log
Allow to reset the templates to the default (#2229) Follow-up to #1956. This commit allows a program to reset any of the tree templates to their default behaviour, as it was possible to do before the change of #1956.
AI Summary
The code change initializes the 'filter' variable to an empty string to prevent 'nounset' errors when the extension is empty. This fix addresses a potential issue where an unbound variable could cause errors in bash completion when no extension is provided.
Commit Log
fix(bash): nounset unbound file filter variable on empty extension (#2228) Happens at least if a flag is marked as filename, with "" given as extensions.
AI Summary
The code adds functionality to print ActiveHelp messages in bash completions, specifically on the second tab press to avoid duplication. It introduces a new function `__%[1]s_handle_activeHelp` to manage the printing of ActiveHelp and ensures it is only shown under specific completion types.
Commit Log
Print ActiveHelp for bash along other completions (#2076) In the bash shell we used to print ActiveHelp messages on every tab-press. In the example below, notice the "Command help" line which is ActiveHelp: bash-5.1$ tanzu context u[tab] Command help: Configure and manage contexts for the Tanzu CLI bash-5.1$ tanzu context u[tab] Command help: Configure and manage contexts for the Tanzu CLI bash-5.1$ tanzu context u unset (Unset the active context so that it is not used by default.) use (Set the context to be used by default) bash-5.1$ tanzu context u Above, on the first [tab] press, only the ActiveHelp is printed. On the second [tab] press, the ActiveHelp is printed again, followed by a re-print of the command-line, followed by the completions choices.
AI Summary
The PR modifies Cobra to allow dead code elimination by restructuring template handling to avoid invoking MethodByName, which inhibits linker optimizations. The changes replace direct template execution with a function wrapper, enabling the linker to remove unused template code paths. A test case is added to verify that dead code elimination works as expected in the default Cobra configuration.
Commit Log
Allow linker to perform deadcode elimination for program using Cobra (#1956) * Restructure code to let linker perform deadcode elimination step Cobra, in its default configuration, will execute a template to generate help, usage and version outputs. Text/template execution calls MethodByName and MethodByName disables dead code elimination in the Go linker, therefore all programs that make use of cobra will be linked with dead code elimination disabled, even if they end up replacing the default usage, help and version formatters with a custom function and no actual text/template evaluations are ever made at runtime. Dead code elimination in the linker helps reduce disk space and memory utilization of programs. For example, for the simple example program used by TestDeadcodeElimination 40% of the final executable size is dead code. For a more realistic example, 12% of the size of Delve's executable is deadcode. This PR changes Cobra so that, in its default configuration, it does not automatically inhibit deadcode elimination by:
AI Summary
The code adds whitespace escape logic to bash v2 completions to handle special characters properly, ensuring they are correctly escaped when displayed or used in the command line. This change aligns the bash v2 completion logic with other completion types, improving consistency and preventing issues with special characters in completion suggestions.
Commit Log
Add similar whitespace escape logic to bash v2 completions than in other completions (#1743)
AI Summary
The code introduces a new type `CompletionFunc` to unify the function signature for completion functions in Cobra, improving type safety and clarity. It updates several methods and variables to use `CompletionFunc` instead of the old function signature, enabling better integration with predefined completion functions like `FixedCompletions` and `NoFileCompletions`.
Commit Log
feat: add CompletionFunc type to help with completions (#2220) Also document that NoFilesCompletion and FixedCompletion can be used with RegisterFlagCompletionFunc.
AI Summary
The comment in the TestPlugin function was updated to clarify its purpose by renaming it to TestPluginWithSubCommands. This change improves documentation clarity but does not alter the function's behavior.
Commit Log
chore: fix function name in comment (#2216)
AI Summary
The code introduces a new SliceValue interface to detect flags that accept multiple values, improving completion support for custom types not following pflag conventions. The change enhances detection by checking if a flag's value implements SliceValue, allowing completion even if the flag is already set.
Commit Log
completion: improve detection for flags that accept multiple values (#2210) The completion code attempts to detect whether a flag can be specified more than once, and therefore should provide completion even if already set. Currently, this code depends on conventions used in the pflag package, which uses an "Array" or "Slice" suffix or for some types a "stringTo" prefix. Cobra allows custom value types to be used, which may not use the same convention for naming, and therefore currently aren't detected to allow multiple values. The pflag module defines a [SliceValue] interface, which is implemented by the Slice and Array value types it provides (unfortunately, it's not currently implemented by the "stringTo" values). This patch adds a reduced interface based on the [SliceValue] interface mentioned above to allow detecting Value-types that accept multiple values.
AI Summary
The code adds a universal check to prevent Cobra from using os.Args during unit tests, ensuring compatibility across different environments and Go versions. The implementation uses a version-specific approach to detect testing environments, supporting both Go 1.21+ and older versions via a custom regex-based check.
Commit Log
Make detection for test-binary more universal (#2173) When running tests in verbose mode (or other options), tests involving Cobra may fail if the test does not explicitly set Command.args to an empty slice; in this case, Cobra defaults to using `os.Args`, which will contain arguments passed to the test (such as `-v` (verbose)). Commits e5762054c9a6429fa7c234897707d and 1ef0913976db2004980575ed815c3 implemented a workaround for this when running (unit) tests for Cobra itself, but this check is specifig to Cobra (checking for `cobra.test`), and don't work on Windows (which will have a `.exe` extension), This patch implements a more universal check, so that users of Cobra as a module also benefit from this workaround. go1.21 and up provides a `testing.Testing()` utility ([1]); as the Cobra module still supports Go1.16 and up, an alternative implementation was added for older versions, based on golang.org/x/mod/lazyregexp [2]. Before this patch:
AI Summary
The commit updates the go-md2man dependency from version 2.0.5 to 2.0.6 to fix compatibility with Go versions prior to go1.17. This change ensures the project can build successfully on older Go versions by using a version of go-md2man that supports them.
Commit Log
build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.5 to 2.0.6 (#2206) fix compatibility with go versions before go1.17 diff: https://github.com/cpuguy83/go-md2man/compare/v2.0.5...v2.0.6
AI Summary
The code updates the go-md2man dependency from version 2.0.4 to 2.0.5 to address a change in how the 'SEE ALSO' section is formatted. The change removes the '.PP' paragraph tag after 'SEE ALSO', which was previously present in version 2.0.4.
Commit Log
Update to latest go-md2man (#2201) Since cpuguy83/go-md2man 2.0.5 no paraTag is written after "SEE ALSO". With go-md2man 2.0.4: .SH SEE ALSO .PP \fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP With go-md2man 2.0.5: .SH SEE ALSO \fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP See: https://github.com/cpuguy83/go-md2man/pull/122
AI Summary
The commit updates links in active_help.md to point to the correct documentation pages. The changes fix broken links by updating the path from 'shell_completions.md' to 'completions/_index.md'.
Commit Log
Fix broken links in active_help.md (#2202) Small change to fix a couple of broken links in active_help.md
AI Summary
The code change modifies PowerShell completion logic to handle constrained mode by returning strings instead of CompletionResult objects. PsCustomObjects are used to avoid issues with hashtables in constrained mode, and checks for FullLanguage mode determine whether to use CompletionResult or return strings.
Commit Log
Make Powershell completion script work in constrained mode (#2196) Creating CompletionResult objects is not allowed in Powershell constrained mode, so return results as strings if constrained mode is enabled Store results as PsCustomObjects instead of hashtables. This prevents Sort-Object from trying to convert the hashtable to a object, which is blocked in constrained mode. PsCustomObjects are created using New-Object to work around https://github.com/PowerShell/PowerShell/issues/20767
AI Summary
The commit adds Azion to the list of CLIs that use cobra. This update is likely to improve visibility and documentation for Azion's CLI tool.
Commit Log
doc: azion project added to the list of CLIs that use cobra (#2198)
AI Summary
The code updates the version flag and help text to use the display name instead of the command name, ensuring consistency in output and improving user experience. It also makes the DisplayName method public to allow external access, which is necessary for plugins to customize display names.
Commit Log
Fix --version help and output for plugins (#2180) * Fix --version help with CommandDisplayNameAnnotation When setting Command.Version, a --version option is added. The help message for the --version command did not consider the command display name: Flags: -h, --help help for kubectl plugin -v, --version version for kubectl-plugin With this change the help test is consistent with other flags: Flags: -h, --help help for kubectl plugin -v, --version version for kubectl plugin * Make command DisplayName() public
AI Summary
The commit improves site formatting by standardizing code blocks, using `console` for command examples, and unifying indentation in project structures. It ensures consistency in documentation by separating titles and code blocks with blank lines and using single import lines in trivial examples.
Commit Log
Improve site formatting (#2183) * Improve site formatting - Separate titles with blank lines - Separate code blocks with blank lines - Always use ``` blocks for examples - Use console for console (bash syntax highlighting does work well with example command output) - Start console examples with $ (highlight command and output differently and more friendly to other shells users) * Unify indentation in example project structure * Use single import line in the trivial examples When we want to show a minimal example with single import it looks cleaner and more minimal with a single line.
AI Summary
The commit updates the README.md file to correct a minor formatting issue in the link text for the Cobra User Guide. The change ensures consistency in the documentation by removing an extra space before the link text.
Commit Log
docs: update README.md (#2197) minor fix
AI Summary
The commit updates the Go version in the test workflow to include Go 1.23. This change ensures compatibility and testing with the latest Go version, which may include new features or bug fixes.
Commit Log
Test also with go 1.23 (#2182)
AI Summary
The code replaces deprecated ioutil functions with standard io and os packages to address golangci-lint warnings and improve compatibility with newer Go versions. The changes involve replacing ioutil.TempDir, ioutil.TempFile, and ioutil.Discard with os.MkdirTemp, os.CreateTemp, and io.Discard respectively.
Commit Log
Replace deprecated ioutil usage (#2181) Fixing golangci-lint errors[1]: Error: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) [1] https://github.com/spf13/cobra/actions/runs/10535452454/job/29194442289?pr=2180
AI Summary
The code change modifies the condition for determining if a flag can be specified multiple times, adding support for 'stringTo' types in addition to 'Array'. This change aims to improve the handling of flags that can be repeated, particularly for string-based flags that map to multiple values.
Commit Log
fix(completions): Complete map flags multiple times (#2174)
AI Summary
The code adds an empty comment line to ensure deprecation comments are properly formatted with whitespace. This change ensures tools like pkg.go.dev can correctly detect deprecated functions.
Commit Log
Fix deprecation comment for Command.SetOutput (#2172) Deprecation comments should be at the start of a paragraph [1], and because of that have a whitespace above them [2]; > To signal that an identifier should not be used, add a paragraph to its > doc comment that begins with Deprecated: followed by some information > about the deprecation (...) With the whitespace missing, some tools, including pkg.go.dev [3] don't detect it to be deprecated. [1]: https://go.dev/wiki/Deprecated [2]: https://go.dev/doc/comment#paragraphs [3]: https://pkg.go.dev/github.com/spf13/[email protected]#Command.SetOutput
AI Summary
The diff updates the .golangci.yml file to replace deprecated linters (gas, megacheck) with their new names (gosec, split into gosimple, staticcheck, unused) and enables additional linters. The changes also include removing commented-out linters and adjusting the configuration to align with the latest golangci-lint version.
Commit Log
Address golangci-lint deprecation warnings, enable some more linters (#2152) * Address golangci-lint linter deprecation warnings 1.59.0 outputs: WARN [lintersdb] The name "gas" is deprecated. The linter has been renamed to: gosec. WARN [lintersdb] The linter named "megacheck" is deprecated. It has been split into: gosimple, staticcheck, unused. * Enable some more linters, address finding
AI Summary
The code diff removes fully inactivated linters (golint, interfacer, maligned) from the .golangci.yml configuration and replaces them with stylecheck, addressing golangci-lint errors. A minor fix is made to the error message in the execute function to correct the capitalization of 'called' to 'called' (likely a typo). The getCompletions function also has a minor fix to correct the capitalization of 'unable' to 'unable' in the error message.
Commit Log
Remove fully inactivated linters (#2148) * Remove fully inactivated linters Currently golangci-lint fails with these errors: ERRO [linters_context] golint: This linter is fully inactivated: it will not produce any reports. ERRO [linters_context] interfacer: This linter is fully inactivated: it will not produce any reports. ERRO [linters_context] maligned: This linter is fully inactivated: it will not produce any reports. I could not find any docs explaining what "fully inactivated" mean, but based this PR[1] it seems that these linters do nothing now. Removing the linters fixes this issue without changing linting, as they did not produce any report. Looking in the linters docs[2] I did not find a replacement for "interfacer" and "malinged" linters. "stylecheck" seems to be a replacement for "golint", but we need to fix the code to enable it. [1] https://github.com/golangci/golangci-lint/pull/4436
AI Summary
The code adds an `Annotation` suffix to private constants to improve clarity and usage in the codebase. This change allows developers to use more descriptive names when referencing annotations, making the code more readable and maintainable.
Commit Log
Consistent annotation names (#2140) Add `Annotation` suffix to the private annotations to allow nicer code using the constants. For example one can use the current annotation names as a temporary variable instead of unclear shortcut. Instead of this: rag := flagsFromAnnotation(c, f, requiredAsGroup) me := flagsFromAnnotation(c, f, mutuallyExclusive) or := flagsFromAnnotation(c, f, oneRequired) We can use now: requiredAsGrop := flagsFromAnnotation(c, f, requiredAsGroupAnnotation) mutuallyExclusive := flagsFromAnnotation(c, f, mutuallyExclusiveAnnotation) oneRequired := flagsFromAnnotation(c, f, oneRequiredAnnotation) Example taken from #2105.
AI Summary
The commit updates the dependency github.com/cpuguy83/go-md2man/v2 from version 2.0.3 to 2.0.4. This change likely addresses bug fixes, security patches, or new features in the go-md2man library.
Commit Log
build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.3 to 2.0.4 (#2127)
AI Summary
The commit updates the user guide documentation for the Cobra project, primarily focusing on flag handling and examples. It includes minor formatting and syntax fixes, such as adding a period to a URL and updating code block syntax.
Commit Log
docs: update user guide (#2128)
AI Summary
The code diff enables gocritic and gosimple linters to improve code quality and address potential issues in the cobra project. The changes include refactoring and simplifying code in various files, such as improving flag handling in bash completions and fixing date formatting in man pages. Some changes involve minor adjustments to string manipulation and test cases, which may affect compatibility or behavior in specific edge cases.
Commit Log
More linting (#2099) * Address gocritic findings, enable it * Enable gosimple, no new findings to address
AI Summary
The code replaces deprecated ioutil.ReadAll with io.ReadAll to align with Go 1.16+ standards. This change ensures compatibility with newer Go versions and avoids deprecation warnings.
Commit Log
fix: remove deprecated io/ioutils package (#2120) ioutils.ReadAll is deprecated since Go 1.16. This commit replaces it with io.ReadAll. See https://pkg.go.dev/io/ioutil\#ReadAll for reference Issue #2119
AI Summary
The code change removes a repeated word ('the') in the comment of two functions, improving clarity and reducing redundancy. This is a minor stylistic change with no functional impact on the code's behavior.
Commit Log
chore: remove repetitive words (#2122)
AI Summary
The commit updates the Go version in the test workflow to 1.22, ensuring compatibility with the latest Go features. This change may affect existing code if it relies on deprecated features or behaviors from Go 1.21.
Commit Log
ci: test golang 1.22 (#2113)
AI Summary
The commit updates the actions/cache dependency from version 3 to 4 in the test workflow. This change likely aims to leverage new features or improvements in the newer version of the cache action.
Commit Log
build(deps): bump actions/cache from 3 to 4 (#2102) Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ...
AI Summary
The commit updates the golangci/golangci-lint-action dependency from version 3.7.0 to 4.0.0 in the GitHub Actions workflow file. This change likely aims to leverage new features, bug fixes, or improvements in the newer version of the linter action.
Commit Log
build(deps): bump golangci/golangci-lint-action from 3.7.0 to 4.0.0 (#2108) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.7.0 to 4.0.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.7.0...v4.0.0) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ...
AI Summary
The commit adds Incus to the list of projects using Cobra. This change is likely to improve visibility and recognition of Cobra's usage in the community.
Commit Log
Add Incus to the list of projects using Cobra (#2118)
AI Summary
The commit adds Taikun CloudWorks to the list of projects using Cobra. This change is likely to increase visibility of Cobra's usage and provide potential users with a real-world example.
Commit Log
Add Taikun CloudWorks to list of projects (#2098)
AI Summary
The code adds documentation clarifying that certain LocalFlags-related functions do not modify the command's state and are used for optimization. These comments help developers understand that the functions are read-only and return the current state without altering it.
Commit Log
flags: clarify documentation that LocalFlags related function do not modify the state (#2064)
AI Summary
The code adds test functions for Levenshtein distance calculation, string in slice check, and right padding to ensure correctness of utility functions. These tests cover various edge cases like case sensitivity, empty strings, and different padding scenarios to validate robustness.
Commit Log
Add tests for funcs in cobra.go (#2094)
AI Summary
The commit adds Zarf to the list of projects using Cobra. This update is likely to improve visibility and recognition of Cobra's ecosystem.
Commit Log
[chore]: update projects using cobra (#2093)
AI Summary
The commit updates the labeler action from version 4 to 5 and adjusts the labeler configuration to be compatible with the new version. The changes include updating the workflow file to use the new version of the labeler action and modifying the labeler.yml file to use the new configuration format.
Commit Log
build(deps): bump actions/labeler from 4 to 5 (#2086) * build(deps): bump actions/labeler from 4 to 5 Bumps [actions/labeler](https://github.com/actions/labeler) from 4 to 5. - [Release notes](https://github.com/actions/labeler/releases) - [Commits](https://github.com/actions/labeler/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/labeler dependency-type: direct:production update-type: version-update:semver-major ... * Update labeler configuration for v5
AI Summary
The code updates the version of the actions/setup-go action from v4 to v5 in the GitHub workflow file to leverage new features or improvements. This change may introduce breaking changes if the new version of setup-go has incompatible changes or requires additional configuration.
Commit Log
build(deps): bump actions/setup-go from 4 to 5 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ...
AI Summary
The code diff removes an unnecessary 'actions/checkout@v4' step from the GitHub Actions workflow. This change likely simplifies the workflow by eliminating redundant steps that were no longer required.
Commit Log
Remove extra actions/checkout
AI Summary
The code change introduces a `displayName()` method to override the command name in help text, ensuring `--help` and default help commands use the display name instead of the raw command name. This addresses an issue where the help text incorrectly displayed the command name instead of the annotated display name, particularly for plugins.
Commit Log
Fix help text for plugins When using `CommandDisplayNameAnnotation` we want to use it instead of the command name in `--help` message or in the default help command. With current code we get the wrong text in the --help usage text: Flags: -h, --help help for kubectl-plugin And in the long description of the default help command: $ kubectl cobraplugin help -h Help provides help for any command in the application. Simply type kubectl-plugin help [path to command] for full details. The issue was hidden since the test checked only the Usage line. Fixed by extracting a displayName() function and use it when creating FlagSet and when formatting the default help flag usage and the help
AI Summary
The code updates the UseLine method to replace the command name with the display name when generating help text for plugins, ensuring correct usage formatting. A new test case is added to verify the behavior of the plugin command without subcommands, addressing an edge case where the display name was not properly reflected.
Commit Log
Fix help text for runnable plugin command When creating a plugin without sub commands, the help text included the command name (kubectl-plugin) instead of the display name (kubectl plugin): Usage: kubectl-plugin [flags] The issue is that the usage line for this case does not use the command path but the raw `Use` string, and this case was not tested. Add a test for this case and fix UsageLine() to replace the command name with the display name. Tested using https://github.com/nirs/kubernetes/tree/sample-cli-plugin-help
AI Summary
The code adds documentation on creating Cobra plugins using the CommandDisplayNameAnnotation to ensure correct display names and completions. The annotation allows plugins to be used with a different name than their executable, improving usability for tools like kubectl.
Commit Log
Document how to create a plugin Using the new CommandDisplayNameAnnotation annotation introduced in Cobra 1.8.0.
AI Summary
The code adds support for an environment variable to suppress completion descriptions in Cobra, allowing users to disable them via `COBRA_COMPLETION_DESCRIPTIONS=0` or `<PROGRAM>_COMPLETION_DESCRIPTIONS=0`. It introduces new functions and constants to handle environment variable configuration and integrates with the completion logic to respect the new flag.
Commit Log
Add env variable to suppress completion descriptions on create (#1938) COBRA_COMPLETION_DESCRIPTIONS=0 or <PROGRAM>_COMPLETION_DESCRIPTIONS=0 can now be used to disable shell completion descriptions.
AI Summary
The commit adds 'Encore' to the list of projects using Cobra, updating the documentation. This change is likely to improve visibility and community recognition of Cobra's usage in the 'Encore' project.
Commit Log
Update projects_using_cobra.md (#2089) Add Encore to the list of projects using Cobra
AI Summary
The code changes focus on micro-optimizations to improve performance by reducing redundant operations such as string splits and preallocating slices and maps. Changes include using SplitN instead of Split to avoid unnecessary splits, preallocating slices for better memory efficiency, and optimizing string handling in completion logic. Potential risks include subtle bugs if the behavior of SplitN differs from Split in specific edge cases, and compatibility issues if the changes affect existing usage patterns.
Commit Log
Micro-optimizations (#1957) * Avoid redundant string splits There likely isn't actually more than once to split in the source strings in these cases, but avoid doing so anyway as we're only interested in the first. * Avoid redundant completion output target evaluations The target is not to be changed while outputting completions, so resolve it only once. * Avoid redundant active help enablement evaluations The enablement state is not to be changed during completion output, so evaluate it only once. * Preallocate some slices and maps with known size
AI Summary
The commit adds LXC to the list of projects using cobra. This change is likely to improve visibility and recognition of cobra's usage in the LXC project.
Commit Log
Add LXC to the list of projects using cobra (#2071)
AI Summary
The code improves the API for retrieving flag completion functions by making it more consistent with the `RegisterFlagCompletionFunc` method and removing a global function to allow for better future flexibility. It now supports persistent flags by using `c.Flag(flagName)` instead of `c.Flags().Lookup(flagName)`, which simplifies flag lookup and improves maintainability. The change includes unit tests to ensure the new API behaves as expected across different flag types and command structures.
Commit Log
Improve API to get flag completion function (#2063) The new API is simpler and matches the `c.RegisterFlagCompletionFunc()` API. By removing the global function `GetFlagCompletion()` we are more future proof if we ever move from a global map of flag completion functions to something associated with the command. The commit also makes this API work with persistent flags by using `c.Flag(flagName)` instead of `c.Flags().Lookup(flagName)`. The commit also adds unit tests.
AI Summary
The code adds support for using cobra commands as plugins for tools like kubectl by modifying the CommandPath method to use a display name from annotations. A new test case is introduced to verify that the plugin usage and help text reflect the correct command format, such as 'kubectl plugin'.
Commit Log
Support usage as plugin for tools like kubectl (#2018) In this case the executable is `kubectl-plugin`, but we run it as: kubectl plugin And the help text should reflect the actual usage of the command. To create a plugin, add the cobra.CommandDisplayNameAnnotation: rootCmd := &cobra.Command{ Use: "plugin", Annotations: map[string]string{ cobra.CommandDisplayNameAnnotation: "kubectl plugin", } } Internally this change modifies CommandPath() for the root command to return the command display name instead of the command name. This is used for error messages, help text generation, and completions.
AI Summary
The commit updates the version of the actions/checkout action from v3 to v4 in multiple workflow jobs. This change is likely to ensure compatibility with newer features, bug fixes, or security updates in the checkout action.
Commit Log
build(deps): bump actions/checkout from 3 to 4 (#2028)
AI Summary
The code replaces all non-alphanumeric characters in the program name for the ActiveHelp environment variable to ensure compatibility with environment variables. This change improves the handling of non-ASCII and special characters in program names, making the environment variable name valid across different systems.
Commit Log
Replace all non-alphanumerics in active help env var program prefix (#1940) * Replace all non-alphanumerics in active help env var program prefix There are other characters besides the dash that are fine in program names, but are problematic in environment variable names. These include (but are not limited to) period, space, and non-ASCII letters. * Another change in docs to mention non-ASCII-alphanumeric instead of just dash
AI Summary
The code adds two tests to verify flag completion registration in cobra, addressing concurrency and persistent flag issues reported in the past. The first test ensures persistent flags registered on a root command are correctly available in subcommands, while the second test checks concurrency safety during flag completion registration.
Commit Log
Add tests for flag completion registration (#2053) Different problems have been reported about flag completion registration. These two tests are the cases that were not being verified but had been mentioned as problematic. Ref: - https://github.com/spf13/cobra/issues/1320 - https://github.com/spf13/cobra/pull/1438#issuecomment-872928669
AI Summary
The change ensures that `--help` and `--version` flags are not automatically completed when `DisableFlagParsing` is set to true, preventing duplicate completions. This avoids conflicts where plugins or commands that disable flag parsing might also define their own completion logic for these flags.
Commit Log
Don't complete --help flag when flag parsing disabled (#2061) Fixes #2060 When a command sets `DisableFlagParsing = true` it requests the responsibility of doing all the flag parsing. Therefore even the `--help/-f/--version/-v` flags should not be automatically completed by Cobra in such a case. Without this change the `--help/-h/--version/-v` flags can end up being completed twice for plugins: one time from cobra and one time from the plugin (which has set `DisableFlagParsing = true`).
AI Summary
The code changes fix linter errors by adding a constant for markdown file extensions and updating string concatenation to use this constant. This ensures consistency in generating markdown file names and avoids hardcoding the extension directly in multiple places.
Commit Log
Fix linter errors (#2052) When using golangci-lint v1.55.0 some new errors were being reported.
AI Summary
The change allows execution of all persistent pre-run and post-run hooks from all parent commands by introducing a global flag EnableTraverseRunHooks. This eliminates the need for workarounds like monkey-patching or manually building hook chains in dependent projects.
Commit Log
Allow running persistent run hooks of all parents (#2044) Currently, only one of the persistent pre-runs and post-runs is executed. It is always the first one found in the parents chain, starting at this command. Expected behavior is to execute all parents' persistent pre-runs and post-runs. Dependent projects implemented various workarounds for this: - manually building persistent hook chains (in every hook). - applying some kind of monkey-patching on top of Cobra. This change eliminates the necessity for such workarounds by allowing to set a global variable EnableTraverseRunHooks. Tickets: - https://github.com/spf13/cobra/issues/216 - https://github.com/spf13/cobra/issues/252
AI Summary
The commit updates the dependency go-md2man from version 2.0.2 to 2.0.3. This change likely aims to incorporate bug fixes, security patches, or new features from the updated library.
Commit Log
build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.2 to 2.0.3 (#2047)
AI Summary
The commit updates the version of the actions/setup-go action from v3 to v4 in the GitHub workflow configuration. This change is likely to ensure compatibility with newer features, bug fixes, or security updates provided in version 4 of the setup-go action.
Commit Log
build(deps): bump actions/setup-go from 3 to 4 (#1934)
AI Summary
The code adds a note clarifying that *PreRun and *PostRun functions are only executed if the Run function is declared. This change improves documentation clarity by specifying the condition under which these lifecycle hooks are triggered.
Commit Log
Add notes to doc on preRun and postRun condition (#2041)
AI Summary
The code adds two new getter functions for retrieving flag completion functions in the cobra library. GetFlagCompletion retrieves a completion function by flag object, while GetFlagCompletionByName retrieves it by flag name.
Commit Log
feat: add getters for flag completions (#1943)
AI Summary
The code adds functionality to customize error message prefixes in Cobra commands, allowing users to set a custom prefix for error messages. It introduces a new field `errPrefix` in the `Command` struct, along with methods `SetErrPrefix` and `ErrPrefix` to manage and retrieve the prefix. The `ExecuteC` method is modified to use the custom error prefix when printing errors, enhancing flexibility in error reporting.
Commit Log
Customizable error message prefix (#2023)
AI Summary
The commit updates the Go version in the test workflow to 1.21, allowing tests to run with Go 1.21. This change ensures compatibility with newer Go features and tools, but may introduce incompatibilities with code relying on older Go versions.
Commit Log
ci: test golang 1.21 (#2024)
AI Summary
The code temporarily disables the gosec G602 check in the findNext function due to a false positive reported in securego/gosec#1005. The change allows the function to return matches[0] without triggering a security warning, which is necessary for correct functionality.
Commit Log
command: temporarily disable G602 due to securego/gosec#1005 (#2022)
AI Summary
The commit updates the golangci-lint-action version from 3.6.0 to 3.7.0 in the test workflow to benefit from new features or bug fixes. This change is likely to improve the reliability or performance of the linter in the CI pipeline without affecting existing functionality.
Commit Log
build(deps): bump golangci/golangci-lint-action from 3.6.0 to 3.7.0 (#2021)
AI Summary
The code changes correct the error messages in unit tests to use 'output' instead of 'err' for consistency. These changes are minor corrections to test output handling and do not alter the test logic or expected behavior.
Commit Log
minor corrections to unit tests (#2003)
AI Summary
The code fixes a typo in the test function name by correcting 'Deperecated' to 'Deprecated'. This change ensures the test function name accurately reflects the intended functionality and improves code readability.
Commit Log
doc: fix typo, Deperecated -> Deprecated (#2000)
AI Summary
The commit updates the .golangci.yml configuration to replace deprecated linters with 'unused'. It disables 'deadcode' and 'structcheck' as they are deprecated and replaced by 'unused'.
Commit Log
golangci: enable 'unused' and disable deprecated replaced by it (#1983)
AI Summary
The code adds support for requiring at least one flag from a group to be present in Cobra commands, enhancing flag validation and completion behavior. New functions like MarkFlagsOneRequired and ValidateFlagGroups are introduced to handle one-required flag groups, with test cases added to ensure correctness. Potential risks include compatibility issues with older versions of Cobra that do not support the one-required flag group feature, and edge cases where flags are not properly annotated or validated.
Commit Log
Add 'one required flag' group (#1952)
AI Summary
The commit updates the version of the golangci-lint-action from 3.5.0 to 3.6.0 in the GitHub Actions workflow. This change likely aims to benefit from new features, bug fixes, or security updates in the newer version of the action.
Commit Log
build(deps): bump golangci/golangci-lint-action from 3.5.0 to 3.6.0 (#1976)
AI Summary
The commit moves documentation sources to a new directory structure under 'site/content', updating internal links to reflect this change. It removes outdated or redundant documentation files like fish_completions.md and powershell_completions.md, redirecting references to the new location.
Commit Log
Move documentation sources to site/content (#1428)
AI Summary
The code change adds curly braces around variable references in PowerShell to properly escape variables containing special characters like dots. This addresses an issue where program names with dots, such as `podman.exe`, were not being handled correctly due to a previous change.
Commit Log
powershell: escape variable with curly brackets (#1960) This fixes an issue with program names that include a dot, in our case `podman.exe`. This was caused by the change in commit 6ba7ebbc. Fixes #1853
AI Summary
The code change improves test robustness by using temporary files instead of relying on the current directory being writable. It replaces `log.Fatal` with `t.Fatal` to ensure test failures are explicitly reported, preventing silent failures.
Commit Log
test: make fish_completions_test more robust (#1980) Use temporary files instead of assuming the current directory is writable. Also, if creating a temporary file still returns an error, prevent the test from failing silently by replacing `log.Fatal` with `t.Fatal`.
AI Summary
The code change fixes grammatical issues in comments and documentation by removing 'to' after verbs like 'allows'. The change was made to address Lintian warnings in Debian packaging, ensuring compliance with style guidelines. The fix is localized to comments and does not affect functionality, but improves readability and adherence to style standards.
Commit Log
Fix grammar: 'allows to' (#1978) The use in generated bash completion files is getting flagged by Lintian (the Debian package linting tool).
AI Summary
The commit updates the version of the golangci-lint-action from 3.4.0 to 3.5.0 in the GitHub Actions workflow. This change likely aims to benefit from new features, bug fixes, or security patches in the newer version of the action.
Commit Log
build(deps): bump golangci/golangci-lint-action from 3.4.0 to 3.5.0 (#1971)
AI Summary
The code fixes a typo in the fish completions by correcting 'Succesfully' to 'Successfully'. This change ensures proper logging in the fish shell completion script, improving clarity and correctness.
Commit Log
Fix typo in fish completions (#1945)
AI Summary
The commit updates the Cobra project's main logo to a new image file named 'CobraMain.png' in the assets directory. The change replaces the previous logo image with a new one, likely to better handle dark background themes as mentioned in the commit message.
Commit Log
Update main image to better handle dark background (#1883) Fixes #1880
AI Summary
The code change allows sourcing the zsh completion script to improve shell completion adoption. It modifies the completion command generation to remove the 'compdef _%[1]s %[1]s' line, which was previously required for zsh completion. This change aligns with the goal of making it easier for users to enable shell completion by sourcing the script directly.
Commit Log
Allow sourcing zsh completion script (#1917) Although it is not the recommended approach, sourcing a completion script is the simplest way to get people to try using shell completion. Not allowing it for zsh has turned out to complicate shell completion adoption. Further, many tools modify the zsh script to allow sourcing. This commit allows sourcing of the zsh completion script.
AI Summary
The commit adds documentation on organizing subcommands in Cobra, suggesting a directory structure with separate files for each subcommand. The approach uses `AddCommand` in `init` functions to define subcommand hierarchies, ensuring compile-time inclusion and avoiding cyclic references.
Commit Log
Document suggested layout for subcommands (#1930)
AI Summary
The commit updates the projects_using_cobra.md file by adding a new project entry for Arewefastyet and updating the Vitess entry. This change is likely to improve the visibility of Cobra's usage in the community and maintain an up-to-date list of projects.
Commit Log
Update projects_using_cobra.md (#1932)
AI Summary
The diff updates the copyright year from 2022 to 2023 across multiple files in the project. This change is likely to ensure the copyright information remains current and accurate.
Commit Log
update copyright year (#1927)
AI Summary
The commit updates the Go version in the test workflow to 1.20, allowing tests to run with this newer version. This change ensures compatibility with Golang 1.20 and may enable new language features or improvements.
Commit Log
ci: test Golang 1.20 (#1925)
AI Summary
The commit deprecates support for Go 1.16 in the CI configuration by removing it from the test matrix. This change likely aims to align the project with newer Go versions and improve compatibility with modern tooling.
Commit Log
ci: deprecate go 1.16 (#1926)
AI Summary
The code change adds support for PowerShell 7.2+ by adjusting how empty arguments are passed, using `"`" for versions before 7.3 or when legacy mode is enabled, and "" otherwise. This ensures compatibility with both older PowerShell versions and newer ones that use the native argument passing feature.
Commit Log
Add support for PowerShell 7.2+ (#1916) PowerShell 7.2 has changed the way arguments are passed to executables. This was originally an experimental feature in 7.2, but as of 7.3 it is built-in. A simple "" is now sufficient for passing empty arguments, no back-tick escaping is required. Fixes #1849
AI Summary
The code adds support for maintaining the order of shell completions by introducing a new directive, ShellCompDirectiveKeepOrder, and modifying completion functions in various shells to respect this directive. It includes checks for shell compatibility, particularly in Bash versions less than 4.4, where the 'nosort' option is not supported.
Commit Log
Add keeporder to shell completion (#1903) This allows programs to request the shell to maintain the order of completions that was returned by the program
AI Summary
The commit removes the GitHub Actions workflow for marking stale issues and pull requests. This change likely aims to disable the bot that automatically labels and closes inactive issues/PRs.
Commit Log
Removes stale bot from GitHub action (#1908)
AI Summary
The commit updates the golangci-lint-action version from 3.3.1 to 3.4.0 in the test workflow to benefit from new features or bug fixes. This change is likely to improve the reliability or performance of the linter in the CI pipeline without affecting existing functionality.
Commit Log
build(deps): bump golangci/golangci-lint-action from 3.3.1 to 3.4.0 (#1902)
AI Summary
The commit updates the documentation to clarify that aliases are only shown in tab completion if no sub-command completions or valid arguments are found. This change aligns the documentation with the current behavior of the completion algorithm in cobra.
Commit Log
Update shell_completions.md (#1907) align documentation with the code : completions.go:452
AI Summary
The code change updates variable names in the User Guide example to improve clarity and consistency. It replaces 'u' and 'pw' with 'ofJson' and 'ofYaml' to better reflect the purpose of the flags.
Commit Log
Improve MarkFlagsMutuallyExclusive example in User Guide (#1904)