Skip to content

Commit

Permalink
Rename packages, commands, module to cobra-cli
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Liggitt <liggitt@google.com>
  • Loading branch information
liggitt committed Feb 10, 2022
1 parent c90e947 commit 627f0c9
Show file tree
Hide file tree
Showing 10 changed files with 808 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -38,7 +38,7 @@ If you have questions regarding Cobra, feel free to ask it in the community
### Quick steps to contribute

1. Fork the project.
1. Download your fork to your PC (`git clone https://github.com/your_username/cobra && cd cobra`)
1. Download your fork to your PC (`git clone https://github.com/your_username/cobra-cli && cd cobra-cli`)
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Make changes and run tests (`make test`)
1. Add them to staging (`git add .`)
Expand Down
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -3,17 +3,17 @@
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`.
Install the cobra generator with the command `go install github.com/spf13/cobra-cli@latest`.
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
Once installed you should have the `cobra-cli` command available. Confirm by typing `cobra-cli` at a
command line.

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

### cobra init
### cobra-cli init

The `cobra init [app]` command will create your initial application code
The `cobra-cli 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.
Expand Down Expand Up @@ -41,7 +41,7 @@ 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
From within a Go module run `cobra-cli 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
Expand All @@ -61,10 +61,10 @@ This is useful if you want to keep your application code separate from your libr

#### Optional flags:
You can provide it your author name with the `--author` flag.
e.g. `cobra init --author "Steve Francia spf@spf13.com"`
e.g. `cobra-cli init --author "Steve Francia spf@spf13.com"`

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

Use the `--viper` flag to automatically setup [viper](https://github.com/spf13/viper)

Expand All @@ -73,7 +73,7 @@ Viper is a companion to Cobra intended to provide easy handling of environment v
### 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`.
add additional commands to your application. The command to do this is `cobra-cli add`.

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

Expand All @@ -84,22 +84,22 @@ Let's say you created an app and you wanted the following commands for it:
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-cli add serve
cobra-cli add config
cobra-cli add create -p 'configCmd'
```

`cobra add` supports all the same optional flags as `cobra init` does (described above).
`cobra-cli add` supports all the same optional flags as `cobra-cli 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.
By default `cobra-cli` 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.*
For example, `cobra-cli add add-user` is incorrect, but `cobra-cli add addUser` is valid.*

Once you have run these three commands you would have an app structure similar to
the following:
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Expand Up @@ -98,7 +98,7 @@ func parseModInfo() (Mod, CurDir) {

// Unsure why, but if no module is present Path is set to this string.
if mod.Path == "command-line-arguments" {
cobra.CheckErr("Please run `go mod init <MODNAME>` before `cobra init`")
cobra.CheckErr("Please run `go mod init <MODNAME>` before `cobra-cli init`")
}

e := modInfoJSON("-e")
Expand Down
2 changes: 1 addition & 1 deletion cmd/init_test.go
Expand Up @@ -17,7 +17,7 @@ func getProject() *Project {
Legal: getLicense(),
Copyright: copyrightLine(),
AppName: "cmd",
PkgName: "github.com/spf13/cobra/cobra/cmd/cmd",
PkgName: "github.com/spf13/cobra-cli/cmd/cmd",
Viper: true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/project.go
Expand Up @@ -6,7 +6,7 @@ import (
"text/template"

"github.com/spf13/cobra"
"github.com/spf13/cobra/cobra/tpl"
"github.com/spf13/cobra-cli/tpl"
)

// Project contains name, license and paths to projects.
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Expand Up @@ -27,7 +27,7 @@ var (
userLicense string

rootCmd = &cobra.Command{
Use: "cobra",
Use: "cobra-cli",
Short: "A generator for Cobra based Applications",
Long: `Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
Expand Down
2 changes: 1 addition & 1 deletion cmd/testdata/main.go.golden
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/
package main

import "github.com/spf13/cobra/cobra/cmd/cmd"
import "github.com/spf13/cobra-cli/cmd/cmd"

func main() {
cmd.Execute()
Expand Down
7 changes: 2 additions & 5 deletions go.mod
@@ -1,11 +1,8 @@
module github.com/spf13/cobra
module github.com/spf13/cobra-cli

go 1.15

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1
github.com/inconshreveable/mousetrap v1.0.0
github.com/spf13/pflag v1.0.5
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
gopkg.in/yaml.v2 v2.4.0
)

0 comments on commit 627f0c9

Please sign in to comment.