Cobra CLI tool to generate applications and commands

Overview

Cobra Generator

Cobra provides its own program that will create your application and add any commands you want. It's the easiest way to incorporate Cobra into your application.

Install the cobra generator with the command go install github.com/spf13/cobra/cobra. Go will automatically install it in your $GOPATH/bin directory which should be in your $PATH.

Once installed you should have the cobra command available. Confirm by typing cobra at a command line.

There are only two operations currently supported by the Cobra generator:

cobra init

The cobra init [app] command will create your initial application code for you. It is a very powerful application that will populate your program with the right structure so you can immediately enjoy all the benefits of Cobra. It can also apply the license you specify to your application.

With the introduction of Go modules, the Cobra generator has been simplified to take advantage of modules. The Cobra generator works from within a Go module.

Initalizing a module

If you already have a module, skip this step.

If you want to initialize a new Go module:

  1. Create a new directory
  2. cd into that directory
  3. run go mod init <MODNAME>

e.g.

cd $HOME/code 
mkdir myapp
cd myapp
go mod init github.com/spf13/myapp

Initalizing an Cobra CLI application

From within a Go module run cobra init. This will create a new barebones project for you to edit.

You should be able to run your new application immediately. Try it with go run main.go.

You will want to open up and edit 'cmd/root.go' and provide your own description and logic.

e.g.

cd $HOME/code/myapp
cobra init
go run main.go

Cobra init can also be run from a subdirectory such as how the cobra generator itself is organized. This is useful if you want to keep your application code separate from your library code.

Optional flags:

You can provide it your author name with the --author flag. e.g. cobra init --author "Steve Francia [email protected]"

You can provide a license to use with --license e.g. cobra init --license apache

Use the --viper flag to automatically setup viper

Viper is a companion to Cobra intended to provide easy handling of environment variables and config files and seamlessly connecting them to the application flags.

Add commands to a project

Once a cobra application is initialized you can continue to use the Cobra generator to add additional commands to your application. The command to do this is cobra add.

Let's say you created an app and you wanted the following commands for it:

  • app serve
  • app config
  • app config create

In your project directory (where your main.go file is) you would run the following:

cobra add serve
cobra add config
cobra add create -p 'configCmd'

cobra add supports all the same optional flags as cobra init does (described above).

You'll notice that this final command has a -p flag. This is used to assign a parent command to the newly added command. In this case, we want to assign the "create" command to the "config" command. All commands have a default parent of rootCmd if not specified.

By default cobra will append Cmd to the name provided and uses this name for the internal variable name. When specifying a parent, be sure to match the variable name used in the code.

Note: Use camelCase (not snake_case/kebab-case) for command names. Otherwise, you will encounter errors. For example, cobra add add-user is incorrect, but cobra add addUser is valid.

Once you have run these three commands you would have an app structure similar to the following:

  ▾ app/
    ▾ cmd/
        config.go
        create.go
        serve.go
        root.go
      main.go

At this point you can run go run main.go and it would run your app. go run main.go serve, go run main.go config, go run main.go config create along with go run main.go help serve, etc. would all work.

You now have a basic Cobra-based application up and running. Next step is to edit the files in cmd and customize them for your application.

For complete details on using the Cobra library, please read the The Cobra User Guide.

Have fun!

Configuring the cobra generator

The Cobra generator will be easier to use if you provide a simple configuration file which will help you eliminate providing a bunch of repeated information in flags over and over.

An example ~/.cobra.yaml file:

author: Steve Francia <[email protected]>
license: MIT
viper: true

You can also use built-in licenses. For example, GPLv2, GPLv3, LGPL, AGPL, MIT, 2-Clause BSD or 3-Clause BSD.

You can specify no license by setting license to none or you can specify a custom license:

author: Steve Francia <[email protected]>
year: 2020
license:
  header: This file is part of CLI application foo.
  text: |
    {{ .copyright }}

    This is my license. There are many like it, but this one is mine.
    My license is my best friend. It is my life. I must master it as I must
    master my life.

In the above custom license configuration the copyright line in the License text is generated from the author and year properties. The content of the LICENSE file is

Copyright © 2020 Steve Francia <[email protected]>

This is my license. There are many like it, but this one is mine.
My license is my best friend. It is my life. I must master it as I must
master my life.

The header property is used as the license header files. No interpolation is done. This is the example of the go file header.

/*
Copyright © 2020 Steve Francia <[email protected]>
This file is part of CLI application foo.
*/
Issues
  • Create `v1.3.0` tag

    Create `v1.3.0` tag

    In support of https://github.com/spf13/cobra/issues/1597, we want to tag this repository with the same "version" that was used before we migrated the code here. This still communicates the version of the cobra CLI but also represents the final tag that the two will correlate.

    In otherwords, this tag is the split in the road that will enable use to seperate cobra from cobra-cli

    The release note for v1.3.0 of this repo will note that all previous history and release markers can be tracked in the spf13/cobra repo.

    If there are no objections, I will do this within the week 👀

    opened by jpmcb 9
  • Initialize cobra-cli repo

    Initialize cobra-cli repo

    This PR sets up various housekeeping things for the new repo:

    • Copies existing license/contributing/conduct/CI root files from spf13/cobra
    • Adds copies of make targets from spf13/cobra, adjust CI config
    • Rename packages and go.mod to cobra-cli
    • Tidy go module

    Because this repo placed the binary at the root, it makes the binary name change to cobra-cli. Before merging any changes into this repo, we should make sure that's what we want, since that ripples to docs and usage, not just the install command (asked in https://github.com/spf13/cobra/issues/1597#issuecomment-1034462012)

    If we want to preserve the cobra binary, we should reinitialize it with the history placed under a github.com/spf13/cobra-cli/cobra subpackage.

    Preview of the configured CI runs passing at https://github.com/liggitt/cobra-cli/actions?query=branch%3Ainit

    opened by liggitt 9
  • Bump actions/stale from 1 to 4.1.0

    Bump actions/stale from 1 to 4.1.0

    Bumps actions/stale from 1 to 4.1.0.

    Release notes

    Sourced from actions/stale's releases.

    v4.1.0

    Features

    v4.0.0

    ⚠️ This version contains breaking changes ⚠️

    Features

    Bug Fixes

    • dry-run: forbid mutations in dry-run (#500) (f1017f3), closes #499
    • logs: coloured logs (#465) (5fbbfba)
    • operations: fail fast the current batch to respect the operations limit (#474) (5f6f311), closes #466
    • label comparison: make label comparison case insensitive #517, closes #516
    • filtering comments by actor could have strange behavior: "stale" comments are now detected based on if the message is the stale message not who made the comment(#519), fixes #441, #509, #518

    Breaking Changes

    • The options skip-stale-issue-message and skip-stale-pr-message were removed. Instead, setting the options stale-issue-message and stale-pr-message will be enough to let the stale workflow add a comment. If the options are unset, a comment will not be added which was the equivalent of setting skip-stale-issue-message to true.
    • The operations-per-run option will be more effective. After migrating, you could face a failed-fast process workflow if you let the default value (30) or set it to a small number. In that case, you will see a warning at the end of the logs (if enabled) indicating that the workflow was stopped sooner to avoid consuming too much API calls. In most cases, you can just increase this limit to make sure to process everything in a single run.

    v3.0.19

    • Enhance logs to provide more detailed output
    • Split certain options to be more granular for Pull Requests vs Issues:
      • any-of-issue-labels
      • any-of-pr-labels
      • remove-issue-stale-when-updated
      • remove-pr-stale-when-updated
    • Dependency updates

    v3.0.18

    • Add any-of-labels option
    • Add only-issue-labels, only-pr-labels
    • Clean up, testing and dependency version bumps

    v3.0.17

    • Bug fixes, refactoring and milestone exemption

    v3.0.16

    • Minor bugfixes and logging improvements

    v3.0.15

    • Add milestone exemption
    • Add start date filtering

    ... (truncated)

    Changelog

    Sourced from actions/stale's changelog.

    Commits
    • 7fb802b Bump release to 4.1.0
    • 54197c7 Merge pull request #602 from actions/revert-breaking-change
    • 3a971ae Revert "Merge pull request #586 from C0ZEN/feature/split-pr-and-issue-options"
    • fc4a5ff Merge pull request #595 from actions/dependabot/npm_and_yarn/types/jest-27.0.2
    • db699ab Merge pull request #586 from C0ZEN/feature/split-pr-and-issue-options
    • f8e08de build(deps-dev): bump @​types/jest from 27.0.1 to 27.0.2
    • b83d488 Update dependencies (#592)
    • 1ff6cd7 build(deps): bump tmpl from 1.0.4 to 1.0.5 (#575)
    • 86fed0e build(deps-dev): bump jest-silent-reporter from 0.4.0 to 0.5.0 (#573)
    • 6700440 docs(readme): split the options between common, issues and prs
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 4
  • Cannot run in docker img: busybox,scratch;  output: . /bin: no such file or directory

    Cannot run in docker img: busybox,scratch; output: . /bin: no such file or directory

    my bin:

    cobra-cli init --viper
    Your Cobra application is ready at ...
    
    sudo docker build -t bin . && sudo docker run -it --rm bin
    Step 1/3 : FROM scratch
    ---> 
    Step 2/3 : COPY ${PWD}/bin .
    ---> f18dcc8e0e25
    Step 3/3 : ENTRYPOINT ["./bin"]
    ---> Running in dc5fd26d812f
    Removing intermediate container dc5fd26d812f
    ---> ee78f634bd9f
    Successfully built ee78f634bd9f
    Successfully tagged bin:latest
    exec ./bin: no such file or directory
    

    my Dockerfile

    FROM scratch
    COPY ${PWD}/bin .
    ENTRYPOINT ["./bin"]
    

    About...

    debian and local is fine golang: 1.18.2 cobra: 1.4.0 viper: 1.11.0

    kind/support 
    opened by szerr 3
  • Bump github.com/spf13/viper from 1.10.1 to 1.11.0

    Bump github.com/spf13/viper from 1.10.1 to 1.11.0

    Bumps github.com/spf13/viper from 1.10.1 to 1.11.0.

    Release notes

    Sourced from github.com/spf13/viper's releases.

    v1.11.0

    What's Changed

    Exciting New Features 🎉

    Enhancements 🚀

    Bug Fixes 🐛

    Breaking Changes 🛠

    Dependency Updates ⬆️

    New Contributors

    Full Changelog: https://github.com/spf13/viper/compare/v1.10.1...v1.11.0

    Commits
    • 6986c0a chore: update crypt
    • 65293ec add release note configuration
    • 6804da7 chore!: drop Go 1.14 support
    • 5b21ca1 fix: deprecated config
    • 55fac10 chore: fix lint
    • e0bf4ac chore: add go 1.18 builds
    • 973c265 build(deps): bump github.com/pelletier/go-toml/v2
    • 129e4f9 build(deps): bump github.com/pelletier/go-toml/v2
    • 9a8603d build(deps): bump actions/setup-go from 2 to 3
    • dc76f3c build(deps): bump github.com/spf13/afero from 1.8.1 to 1.8.2
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 3
  • Bump github.com/spf13/cobra from 1.3.0 to 1.4.0

    Bump github.com/spf13/cobra from 1.3.0 to 1.4.0

    Bumps github.com/spf13/cobra from 1.3.0 to 1.4.0.

    Release notes

    Sourced from github.com/spf13/cobra's releases.

    v1.4.0

    Winter 2022 Release ❄️

    Another season, another release!

    Goodbye viper! 🐍 🚀

    The core Cobra library no longer requires Viper and all of its indirect dependencies. This means that Cobra's dependency tree has been drastically thinned! The Viper dependency was included because of the cobra CLI generation tool. This tool has migrated to spf13/cobra-cli.

    It's pretty unlikely you were importing and using the bootstrapping CLI tool as part of your application (after all, it's just a tool to get going with core cobra).

    But if you were, replace occurrences of

    "github.com/spf13/cobra/cobra"
    

    with

    "github.com/spf13/cobra-cli"
    

    And in your go.mod, you'll want to also include this dependency:

    github.com/spf13/cobra-cli v1.3.0
    

    Again, the maintainers do not anticipate this being a breaking change to users of the core cobra library, so minimal work should be required for users to integrate with this new release. Moreover, this means the dependency tree for your application using Cobra should no longer require dependencies that were inherited from Viper. Huzzah! 🥳

    If you'd like to read more

    Documentation 📝

    Other 💭

    Shoutout to our awesome contributors helping to make this cobra release possible!! @​spf13 @​marckhouzam @​johnSchnake @​jpmcb @​liggitt @​umarcor @​hiljusti @​marians @​shyim @​htroisi

    Changelog

    Sourced from github.com/spf13/cobra's changelog.

    Cobra Changelog

    v1.1.3

    • Fix: release-branch.cobra1.1 only: Revert "Deprecate Go < 1.14" to maintain backward compatibility

    v1.1.2

    Notable Changes

    • Bump license year to 2021 in golden files (#1309) @​Bowbaq
    • Enhance PowerShell completion with custom comp (#1208) @​Luap99
    • Update gopkg.in/yaml.v2 to v2.4.0: The previous breaking change in yaml.v2 v2.3.0 has been reverted, see go-yaml/yaml#670
    • Documentation readability improvements (#1228 etc.) @​zaataylor etc.
    • Use golangci-lint: Repair warnings and errors resulting from linting (#1044) @​umarcor

    v1.1.1

    • Fix: yaml.v2 2.3.0 contained a unintended breaking change. This release reverts to yaml.v2 v2.2.8 which has recent critical CVE fixes, but does not have the breaking changes. See spf13/cobra#1259 for context.
    • Fix: correct internal formatting for go-md2man v2 (which caused man page generation to be broken). See spf13/cobra#1049 for context.

    v1.1.0

    Notable Changes

    • Extend Go completions and revamp zsh comp (#1070)
    • Fix man page doc generation - no auto generated tag when cmd.DisableAutoGenTag = true (#1104) @​jpmcb
    • Add completion for help command (#1136)
    • Complete subcommands when TraverseChildren is set (#1171)
    • Fix stderr printing functions (#894)
    • fix: fish output redirection (#1247)

    v1.0.0

    Announcing v1.0.0 of Cobra. 🎉

    Notable Changes

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 3
  • Bump actions/cache from 2 to 3

    Bump actions/cache from 2 to 3

    Bumps actions/cache from 2 to 3.

    Release notes

    Sourced from actions/cache's releases.

    v3.0.0

    • This change adds a minimum runner version(node12 -> node16), which can break users using an out-of-date/fork of the runner. This would be most commonly affecting users on GHES 3.3 or before, as those runners do not support node16 actions and they can use actions from github.com via github connect or manually copying the repo to their GHES instance.

    • Few dependencies and cache action usage examples have also been updated.

    v2.1.7

    Support 10GB cache upload using the latest version 1.0.8 of @actions/cache

    v2.1.6

    • Catch unhandled "bad file descriptor" errors that sometimes occurs when the cache server returns non-successful response (actions/cache#596)

    v2.1.5

    • Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (actions/cache#527)

    v2.1.4

    • Make caching more verbose #650
    • Use GNU tar on macOS if available #701

    v2.1.3

    • Upgrades @actions/core to v1.2.6 for CVE-2020-15228. This action was not using the affected methods.
    • Fix error handling in uploadChunk where 400-level errors were not being detected and handled correctly

    v2.1.2

    • Adds input to limit the chunk upload size, useful for self-hosted runners with slower upload speeds
    • No-op when executing on GHES

    v2.1.1

    • Update @actions/cache package to v1.0.2 which allows cache action to use posix format when taring files.

    v2.1.0

    • Replaces the http-client with the Azure Storage SDK for NodeJS when downloading cache content from Azure. This should help improve download performance and reliability as the SDK downloads files in 4 MB chunks, which can be parallelized and retried independently
    • Display download progress and speed
    Commits
    • 4b0cf6c Merge pull request #769 from actions/users/ashwinsangem/bump_major_version
    • 60c606a Update licensed files
    • b6e9a91 Revert "Updated to the latest version."
    • c842503 Updated to the latest version.
    • 2b7da2a Bumped up to a major version.
    • deae296 Merge pull request #651 from magnetikonline/fix-golang-windows-example
    • c7c46bc Merge pull request #707 from duxtland/main
    • 6535c5f Regenerated examples.md TOC
    • 3fdafa4 Update GitHub Actions status badge markdown in README.md
    • 341e6d7 Merge branch 'actions:main' into fix-golang-windows-example
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 2
  • Regression: Unknown license with the `--license <my-file>.yaml` flag

    Regression: Unknown license with the `--license .yaml` flag

    Looks like a regression that was previously fixed has been reintroduced between 1.2.1 and 1.3.0 and effects 1.4.0 and then got migrated along to this new repository. I get an error when I try to specify a custom license.

    https://github.com/spf13/cobra/issues/321

    Error: unknown license: /Users/paul/.my-license.yaml
    

    I have a template that I use for my license, here is an example of what it looks like:

    author: Me
    license:
      header: Buy me a covfefe?
      text: |
        {{ .copyright }}
    

    To recreate:

    $ go install github.com/spf13/[email protected]
    $ mkdir example
    $ cd example
    $ go mod init example
    $ cobra-cli init --license ~/.my-license.yaml
    > Error: unknown license: /Users/paul/.my-license.yaml
    
    opened by paul-nelson-baker 2
  • Constructors boilerplate

    Constructors boilerplate

    • This is not my final image of how the commands should be constructed but my final image would require to work with the Go AST library which I am not familiar with and imo might be overkill.
    • I usually do call rootCmd.AddCommand(NewSubCommand()) inside of the constructor NewRootCmd() which would be quite hard to do with generated code. cobra-cli would need to actually parse generated Go code and append lines at specific locations for that to work with sub commands that are added afterwards.

    That's way too much work so I did go a slightly easier way. Might not be the final stage but definitely a step forward.

    (removed the accidental dependably stuff)

    opened by jxsl13 2
  • Bump golangci/golangci-lint-action from 2 to 3.1.0

    Bump golangci/golangci-lint-action from 2 to 3.1.0

    Bumps golangci/golangci-lint-action from 2 to 3.1.0.

    Release notes

    Sourced from golangci/golangci-lint-action's releases.

    v3.1.0

    What's Changed

    New features

    CI

    Dependabot

    Misc

    New Contributors

    Full Changelog: https://github.com/golangci/golangci-lint-action/compare/v3...v3.1.0

    v3.0.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/golangci/golangci-lint-action/compare/v2...v3.0.0

    Bump version v2.5.2

    Bug fixes

    • 5c56cd6 Extract and don't mangle User Args. (#200)

    Dependencies

    • e3c53fe bump @​typescript-eslint/eslint-plugin (#194)
    • 3b9f80e bump @​typescript-eslint/parser from 4.18.0 to 4.19.0 (#195)
    • 9845713 bump @​types/node from 14.14.35 to 14.14.37 (#197)
    • e789ee1 bump eslint from 7.22.0 to 7.23.0 (#196)
    • f2e9a96 bump @​typescript-eslint/eslint-plugin (#188)
    • 818081a bump @​types/node from 14.14.34 to 14.14.35 (#189)
    • 6671836 bump @​typescript-eslint/parser from 4.17.0 to 4.18.0 (#190)

    ... (truncated)

    Commits
    • b517f99 fix version in package-lock.json (#407)
    • 9636c5b Update version to 3.1.0 in package.json (#406)
    • 03e4bef ci(dep): Add step to commit changes if PR has dependencies label (#108)
    • cdfc708 Allow to disable caching completely (#351)
    • 7d5614c build(deps-dev): bump eslint from 8.9.0 to 8.10.0 (#405)
    • c675eb7 Update all direct dependencies (#404)
    • 423fbaf Remove Setup-Go (#403)
    • bcfc6f9 build(deps-dev): bump eslint-plugin-import from 2.25.3 to 2.25.4 (#402)
    • d34ac2a build(deps): bump setup-go from v2.1.4 to v2.2.0 (#401)
    • e4b538e build(deps-dev): bump @​types/node from 16.11.10 to 17.0.19 (#400)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 2
  • Add .vscode to .gitignore

    Add .vscode to .gitignore

    I use the Go debugger through VSCode and the debugger launch files are stored under .vscode/. This one-liner simply .vscode/ adds it to the .gitignore file.

    opened by marckhouzam 2
  • Bump github.com/spf13/viper from 1.10.1 to 1.12.0

    Bump github.com/spf13/viper from 1.10.1 to 1.12.0

    Bumps github.com/spf13/viper from 1.10.1 to 1.12.0.

    Release notes

    Sourced from github.com/spf13/viper's releases.

    v1.12.0

    This release makes YAML v3 and TOML v2 the default versions used for encoding.

    You can switch back to the old versions by adding viper_yaml2 and viper_toml1 to the build tags.

    Please note that YAML v2 and TOML v1 are considered deprecated from this release and may be removed in a future release.

    Please provide feedback in discussions and report bugs on the issue tracker. Thanks!

    What's Changed

    Exciting New Features 🎉

    Enhancements 🚀

    Dependency Updates ⬆️

    New Contributors

    Full Changelog: https://github.com/spf13/viper/compare/v1.11.0...v1.12.0

    v1.11.0

    What's Changed

    Exciting New Features 🎉

    Enhancements 🚀

    Bug Fixes 🐛

    ... (truncated)

    Commits
    • 4322cf2 feat: make toml2 the default
    • 8d02999 feat: make yaml3 the default
    • 7c35aa9 chore(deps): update yaml3
    • 433821f feat: add etcd3 support to remote
    • 2080d43 chore: update crypt
    • da55858 chore: fix Error log calls in mergeMaps
    • f50ce90 Add in MustBindEnv.
    • 3b836e5 build(deps): bump github.com/subosito/gotenv from 1.2.0 to 1.3.0
    • 5d65186 build(deps): bump github.com/pelletier/go-toml/v2 from 2.0.0 to 2.0.1
    • 9f85518 build(deps): bump github.com/spf13/cast from 1.4.1 to 1.5.0
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 1
  • Bump golangci/golangci-lint-action from 2 to 3

    Bump golangci/golangci-lint-action from 2 to 3

    Bumps golangci/golangci-lint-action from 2 to 3.

    Release notes

    Sourced from golangci/golangci-lint-action's releases.

    v3.0.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/golangci/golangci-lint-action/compare/v2...v3.0.0

    Bump version v2.5.2

    Bug fixes

    • 5c56cd6 Extract and don't mangle User Args. (#200)

    Dependencies

    • e3c53fe bump @​typescript-eslint/eslint-plugin (#194)
    • 3b9f80e bump @​typescript-eslint/parser from 4.18.0 to 4.19.0 (#195)
    • 9845713 bump @​types/node from 14.14.35 to 14.14.37 (#197)
    • e789ee1 bump eslint from 7.22.0 to 7.23.0 (#196)
    • f2e9a96 bump @​typescript-eslint/eslint-plugin (#188)
    • 818081a bump @​types/node from 14.14.34 to 14.14.35 (#189)
    • 6671836 bump @​typescript-eslint/parser from 4.17.0 to 4.18.0 (#190)
    • 526907e bump @​typescript-eslint/parser from 4.16.1 to 4.17.0 (#185)
    • 6b6ba16 bump @​typescript-eslint/eslint-plugin (#186)
    • 9cab4ef bump eslint from 7.21.0 to 7.22.0 (#187)
    • 0c76572 bump @​types/node from 14.14.32 to 14.14.34 (#184)
    • 0dfde21 bump @​typescript-eslint/parser from 4.15.2 to 4.16.1 (#182)
    • 9dcf389 bump typescript from 4.2.2 to 4.2.3 (#181)
    • 34d3904 bump @​types/node from 14.14.31 to 14.14.32 (#180)
    • e30b22f bump @​typescript-eslint/eslint-plugin (#179)
    • 8f30d25 bump eslint from 7.20.0 to 7.21.0 (#177)
    • 0b64a40 bump @​typescript-eslint/parser from 4.15.1 to 4.15.2 (#176)
    • 973b3a3 bump eslint-config-prettier from 8.0.0 to 8.1.0 (#178)
    • 6ea3de1 bump @​typescript-eslint/eslint-plugin (#175)
    • 6eec6af bump typescript from 4.1.5 to 4.2.2 (#174)

    v2.5.1

    Bug fixes:

    • d9f0e73 Check that go.mod exists in reading the version (#173)

    v2.5.0

    New Features:

    • 51485a4 Try to get version from go.mod file (#118)

    ... (truncated)

    Commits
    • b517f99 fix version in package-lock.json (#407)
    • 9636c5b Update version to 3.1.0 in package.json (#406)
    • 03e4bef ci(dep): Add step to commit changes if PR has dependencies label (#108)
    • cdfc708 Allow to disable caching completely (#351)
    • 7d5614c build(deps-dev): bump eslint from 8.9.0 to 8.10.0 (#405)
    • c675eb7 Update all direct dependencies (#404)
    • 423fbaf Remove Setup-Go (#403)
    • bcfc6f9 build(deps-dev): bump eslint-plugin-import from 2.25.3 to 2.25.4 (#402)
    • d34ac2a build(deps): bump setup-go from v2.1.4 to v2.2.0 (#401)
    • e4b538e build(deps-dev): bump @​types/node from 16.11.10 to 17.0.19 (#400)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions kind/stale 
    opened by dependabot[bot] 2
  • Bump actions/setup-go from 2 to 3

    Bump actions/setup-go from 2 to 3

    Bumps actions/setup-go from 2 to 3.

    Release notes

    Sourced from actions/setup-go's releases.

    v3.0.0

    What's Changed

    Breaking Changes

    With the update to Node 16, all scripts will now be run with Node 16 rather than Node 12.

    This new major release removes the stable input, so there is no need to specify additional input to use pre-release versions. This release also corrects the pre-release versions syntax to satisfy the SemVer notation (1.18.0-beta1 -> 1.18.0-beta.1, 1.18.0-rc1 -> 1.18.0-rc.1).

    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          go-version: '1.18.0-rc.1' 
      - run: go version
    

    Add check-latest input

    In scope of this release we add the check-latest input. If check-latest is set to true, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded from go-versions repository. By default check-latest is set to false. Example of usage:

    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          go-version: '1.16'
          check-latest: true
      - run: go version
    

    Moreover, we updated @actions/core from 1.2.6 to 1.6.0

    v2.1.5

    In scope of this release we updated matchers.json to improve the problem matcher pattern. For more information please refer to this pull request

    v2.1.4

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/setup-go/compare/v2.1.3...v2.1.4

    v2.1.3

    • Updated communication with runner to use environment files rather then workflow commands

    v2.1.2

    This release includes vendored licenses for this action's npm dependencies.

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • Bump actions/cache from 2 to 3.0.1

    Bump actions/cache from 2 to 3.0.1

    Bumps actions/cache from 2 to 3.0.1.

    Release notes

    Sourced from actions/cache's releases.

    v3.0.1

    • Added support for caching from GHES 3.5.
    • Fixed download issue for files > 2GB during restore.

    v3.0.0

    • This change adds a minimum runner version(node12 -> node16), which can break users using an out-of-date/fork of the runner. This would be most commonly affecting users on GHES 3.3 or before, as those runners do not support node16 actions and they can use actions from github.com via github connect or manually copying the repo to their GHES instance.

    • Few dependencies and cache action usage examples have also been updated.

    v2.1.7

    Support 10GB cache upload using the latest version 1.0.8 of @actions/cache

    v2.1.6

    • Catch unhandled "bad file descriptor" errors that sometimes occurs when the cache server returns non-successful response (actions/cache#596)

    v2.1.5

    • Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (actions/cache#527)

    v2.1.4

    • Make caching more verbose #650
    • Use GNU tar on macOS if available #701

    v2.1.3

    • Upgrades @actions/core to v1.2.6 for CVE-2020-15228. This action was not using the affected methods.
    • Fix error handling in uploadChunk where 400-level errors were not being detected and handled correctly

    v2.1.2

    • Adds input to limit the chunk upload size, useful for self-hosted runners with slower upload speeds
    • No-op when executing on GHES

    v2.1.1

    • Update @actions/cache package to v1.0.2 which allows cache action to use posix format when taring files.

    v2.1.0

    • Replaces the http-client with the Azure Storage SDK for NodeJS when downloading cache content from Azure. This should help improve download performance and reliability as the SDK downloads files in 4 MB chunks, which can be parallelized and retried independently
    • Display download progress and speed
    Changelog

    Sourced from actions/cache's changelog.

    3.0.1

    • Added support for caching from GHES 3.5.
    • Fixed download issue for files > 2GB during restore.
    Commits
    • 136d96b Enabling actions/cache for GHES based on presence of AC service (#774)
    • 7d4f40b Bumping up the version to fix download issue for files > 2 GB. (#775)
    • 2d8d0d1 Updated what's new. (#771)
    • 7799d86 Updated the usage and docs to the major version release. (#770)
    • 4b0cf6c Merge pull request #769 from actions/users/ashwinsangem/bump_major_version
    • 60c606a Update licensed files
    • b6e9a91 Revert "Updated to the latest version."
    • c842503 Updated to the latest version.
    • 2b7da2a Bumped up to a major version.
    • deae296 Merge pull request #651 from magnetikonline/fix-golang-windows-example
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions kind/stale 
    opened by dependabot[bot] 2
  • Go 1.18 workspace support in cobra-cli init

    Go 1.18 workspace support in cobra-cli init

    When attempting to use cobra-cli init in a project that uses Go 1.18's new workspace mode, I hit what looks like a JSON unmarshaling error (Error: invalid character '{' after top-level value) and initializing fails.

    My apologies in advance if I'm misunderstanding any aspect of workspaces, modules, or cobra-cli here - I'm fairly new to Go, but expecting this might be a new edge case in 1.18 due to workspaces.

    Steps to reproduce

    mkdir cli-playground && cd cli-playground
    go work init
    mkdir project1 && cd project1 && go mod init project1 && cd ..
    mkdir project2 && cd project2 && go mod init project2 && cd ..
    go work use project1 project2
    cd project2
    cobra-cli init
    #=> go: creating new go.mod: module project1
    #=> go: creating new go.mod: module project2
    #=> Error: invalid character '{' after top-level value
    

    I believe this is because go list -json -m returns a stream of JSON objects with relevant modules, whereas this bit of code expects to consume a single JSON object.

    I spiked out a test in investigating this behavior, which exposes the same behavior as above. But I’m guessing that approach only works for Go 1.18+, and cobra-cli probably wants to support earlier versions. As far as a fix (if we agree it's worth addressing), I was thinking that the parseModInfo operations could potentially allow using the current directory (from the output of go list -json -e) to decide which of the JSON objects to use. Thoughts?

    Workaround

    Removing all projects from the workspace except the one I want to cobra-cli init does let things work, and that's good enough to unblock me.

    Additional potential gotcha

    In experimenting with removing workspace items, there's another case that has surprising (to me) behavior: if we try running cobra-cli init on a module that's not yet included in the workspace.

    mkdir cli-playground && cd cli-playground
    go work init
    mkdir project1 && cd project1 && go mod init project1 && cd ..
    mkdir project2 && cd project2 && go mod init project2 && cd ..
    go work use project1
    cd project2
    cobra-cli init
    

    The above appears to succeed, but the contents of project2/main.go are now:

    /*
    Copyright © 2022 NAME HERE <EMAIL ADDRESS>
    
    */
    package main
    
    import "project1/tmp/cli-playground/project2/cmd"
    
    func main() {
            cmd.Execute()
    }
    

    I'm honestly not sure what behavior I'd expect here, since the module isn't in the workspace. But the import path project1/tmp/cli-playground/project2/cmd looks pretty wrong to me (note both project1 and project2 in that path, despite them being peers). I can totally understand this scenario being unsupported / undefined behavior,

    But I thought it could be useful to include it in this report, both because I think the existing behavior is kind of surprising (I might personally prefer an error), and more importantly because I imagine that the choice of which module to pick from the list in go list -json -m could potentially create better behavior here.

    kind/stale 
    opened by trptcolin 3
Releases(v1.3.0)
  • v1.3.0(Mar 2, 2022)

    Welcome! 👋🏼 🐍

    This is the first release of cobra-cli, the CLI bootstrapper for spf13/cobra! 🎉 Originally, this code and the CLI tool existed directly in spf13/cobra, co-located as a single go module. But it was migrated here to enable the core cobra library to be as lite-weight and easy to consume as possible.

    For further context, refer to: https://github.com/spf13/cobra/issues/1597

    How do I migrate? 🥡

    It's pretty unlikely you were importing and using the bootstrapping CLI tool as part of your application (after all, it's just a tool to get going with core cobra).

    But if you were, replace occurrences of

    "github.com/spf13/cobra/cobra"
    

    with

    "github.com/spf13/cobra-cli"
    

    In your go.mod, you'll want to also include this dependency. We recommend getting it by

    github.com/spf13/cobra-cli v1.3.0
    

    Different repos 🍴

    Now that spf13/cobra and spf13/cobra-cli are separated, this means they will likely diverge in their versioning scheme. We started with a v1.3.0 because it's the same code and things from spf13/cobra's v1.3.0 tag. Or in other-words, this release merely represents the changing of repositories and the changing of names. In the future, these version numbers may drift and will not continue to be directly correlated.

    Shoutout to our awesome contributors helping to make this happen! @spf13 @marckhouzam @johnSchnake @liggitt

    Source code(tar.gz)
    Source code(zip)
Owner
Steve Francia
13x engineer • @golang Product Lead @Google • Prior EVP @Docker, @MongoDB, @Drupal board • @gohugoio, Cobra & spf13-vim creator
Steve Francia
Generate an interactive, autocompleting shell for any Cobra CLI

cobra-shell Description Leverages the Cobra completion API to generate an interactive shell for any Cobra CLI, powered by go-prompt. On-the-fly autoco

Brian Strauch 25 Apr 23, 2022
Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Dipto Chakrabarty 2 Jan 2, 2022
painless task queue manager for shell commands with an intuitive cli interface (execute shell commands in distributed cloud-native queue manager).

EXEQ DOCS STILL IN PROGRESS. Execute shell commands in queues via cli or http interface. Features Simple intuitive tiny cli app. Modular queue backend

Mohammed Al Ashaal 12 Jan 29, 2022
CLI to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Aniruddha Chattopadhyay 0 Dec 20, 2021
Build an interactive CLI application with Go, Cobra and promptui. Video tutorial available on the Div Rhino YouTube channel.

Build an interactive CLI app with Go, Cobra and promptui Text tutorial: https://divrhino.com/articles/build-interactive-cli-app-with-go-cobra-promptui

Div Rhino Dev 14 Jun 3, 2022
Simple CLI using spf13/cobra and Flink REST API

Flinkctl Flinkctl is a simple CLI written on Go using Cobra created to facilitate my team's daily basis work with multiple Flink clusters at Azion Tec

Tiago Krebs 2 Sep 8, 2021
A cli client-server app with cobra

cli-client-server-calculator a cli client-server app with cobra overview this project is a cli client-server app in which client gives a bunch of numb

mohammad-hossein zeynal zadeh 5 Dec 7, 2021
Cobra CLI challenge Segsalerty

Banking app done using Cobra CLI - Segsalerty challenge c/o Segun Mustafa It uses a database.json file as datastore for queries - createCustomer, Upda

Oladapo Olawale Sunday 0 Dec 14, 2021
This project is used to get familiar with GoLang cli apps, along with cobra generator.

SecretCTL SecretCTL About the project Status Getting started Layout Notes About the project This project is used to get familiar with GoLang cli apps,

Milos Folic 0 Jan 11, 2022
It‘s a cmd-line tool like `make` and `task`, supporting nested args and alias using `cobra`

It‘s a cmd-line tool like `make` and `task`, supporting nested args and alias using `cobra`. It's a makefile alternative and a shell wrapper.

null 2 Apr 14, 2022
The blackbean is a command tool for elasticsearch operations by using cobra.

The blackbean is a command tool for elasticsearch operations by using cobra. Besides, blackbean is the name of my lovely French bulldog.

null 23 Mar 3, 2022
Effortlessly generate chmod commands

?? CHMOD-CLI Simple cli tool that brings the chmod command in tui format. Genera

Mayowa Ojo 146 Jun 15, 2022
A CLI tool for running Go commands with colorized output

Goli Goli is a CLI Tool for running Go commands with colorized output. Note: Goli is still a WIP. It has very basic commands and limitations. Feel fre

Arthur Diniz 14 May 3, 2022
Reusable golang-migrate library using cobra utility

shift Reusable golang-migrate library using cobra utility Example Usage package main import ( "sql/db" "github.com/purwandi/shift" "github.com

purwandi 0 Dec 16, 2021
command argument completion generator for spf13/cobra

Command argument completion generator for cobra. You can read more about it here: A pragmatic approach to shell completion.

null 39 Jun 9, 2022
Gobby-cli - CLI application to debug gobby applications

go(bby) Interactive debugging tool for gobby applications Usage Coming soon™ Ins

Qwiri 0 Feb 8, 2022
A CLI to execute AT Commands via serial port connections.

AT Command CLI A CLI to execute AT Commands via serial port connections. Development Install Go Run go run main.go

Daniel Khaapamyaki 22 Jun 19, 2022
Command-line tool to load csv and excel (xlsx) files and run sql commands

csv-sql supports loading and saving results as CSV and XLSX files with data processing with SQLite compatible sql commands including joins.

Dhamith Hewamullage 22 May 6, 2022