Simple boilerplate to create CLI applications with Go
-
Clone this repo and enter it
-
Run
docker build -t "mytag" .
-
Run
docker run -it --rm mytag hello
-
Clone this repo and enter it
-
Run
go get ./...
-
Run
go run app.go hello
or build the application withgo build
and execute the binary like:./app hello
-
The
cmd
module is where you will create your commands. Create a file for each command following the example ofcmd/hello.go
-
The
flag_variables.go
is used to declare variables that will receive the flags values, I did this to reuse the variables instead of creating new ones for each command.- Example: If have two commands with the variable
var source string
. You can declare thesource
incommand A
file and reuse it incommand B
file but it will get messy to know where the variables are declared. You can create a new variable but probably it will have a name almost equal tosource
and it's redundant because they're for the same thing.
- Example: If have two commands with the variable
-
The
core
module is where you put things that's common and/or can be used to all your application like the application configuration- The
config.go
offers basic methods to work with the application configuration, you can create your own methods here - The
init.go
is where you put things that you will expose to other packages like theAppConfiguration
- The
Bug reports and pull requests are welcome on GitHub at https://github.com/WendellAdriel/go-simple-cli-boilerplate/. This project is intended to be a safe, welcoming space for collaboration.
This project is available as open source under the terms of the MIT License.