Skip to content

Commit 6eae9c9

Browse files
committed
site: move documentation about CLI
1 parent 97aedd7 commit 6eae9c9

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

cobra/README.md renamed to site/content/CLI.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
# Cobra Generator
1+
# Cobra Generator CLI tool
22

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

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

9-
Once installed you should have the `cobra` command available. Confirm by typing `cobra` at a
10-
command line.
9+
Once installed you should have the `cobra` command available. Confirm by typing `cobra` at a
10+
command line.
1111

12-
There are only two operations currently supported by the Cobra generator:
12+
There are only two operations currently supported by the Cobra generator:
1313

1414
### cobra init
1515

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

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

2424
#### Initalizing a module
2525

2626
__If you already have a module, skip this step.__
2727

28-
If you want to initialize a new Go module:
28+
If you want to initialize a new Go module:
2929

30-
1. Create a new directory
30+
1. Create a new directory
3131
2. `cd` into that directory
3232
3. run `go mod init <MODNAME>`
3333

34-
e.g.
34+
e.g.
3535
```
36-
cd $HOME/code
36+
cd $HOME/code
3737
mkdir myapp
3838
cd myapp
3939
go mod init github.com/spf13/myapp
@@ -42,12 +42,12 @@ go mod init github.com/spf13/myapp
4242
#### Initalizing an Cobra CLI application
4343

4444
From within a Go module run `cobra init`. This will create a new barebones project
45-
for you to edit.
45+
for you to edit.
4646

47-
You should be able to run your new application immediately. Try it with
48-
`go run main.go`.
47+
You should be able to run your new application immediately. Try it with
48+
`go run main.go`.
4949

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

5252
e.g.
5353
```
@@ -60,10 +60,10 @@ Cobra init can also be run from a subdirectory such as how the [cobra generator
6060
This is useful if you want to keep your application code separate from your library code.
6161

6262
#### Optional flags:
63-
You can provide it your author name with the `--author` flag.
63+
You can provide it your author name with the `--author` flag.
6464
e.g. `cobra init --author "Steve Francia [email protected]"`
6565

66-
You can provide a license to use with `--license`
66+
You can provide a license to use with `--license`
6767
e.g. `cobra init --license apache`
6868

6969
Use the `--viper` flag to automatically setup [viper](https://github.com/spf13/viper)
@@ -72,8 +72,8 @@ Viper is a companion to Cobra intended to provide easy handling of environment v
7272

7373
### Add commands to a project
7474

75-
Once a cobra application is initialized you can continue to use the Cobra generator to
76-
add additional commands to your application. The command to do this is `cobra add`.
75+
Once a cobra application is initialized you can continue to use the Cobra generator to
76+
add additional commands to your application. The command to do this is `cobra add`.
7777

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

@@ -93,9 +93,9 @@ cobra add create -p 'configCmd'
9393

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

98-
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.
98+
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.
9999

100100
*Note: Use camelCase (not snake_case/kebab-case) for command names.
101101
Otherwise, you will encounter errors.

0 commit comments

Comments
 (0)