https://github.com/metafates/go-template
☄️ Powerful template for Go CLI projects with advanced config management
https://github.com/metafates/go-template
cli go template
Last synced: about 1 year ago
JSON representation
☄️ Powerful template for Go CLI projects with advanced config management
- Host: GitHub
- URL: https://github.com/metafates/go-template
- Owner: metafates
- Created: 2022-09-24T17:52:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-15T16:06:32.000Z (about 3 years ago)
- Last Synced: 2025-03-28T02:53:33.644Z (about 1 year ago)
- Topics: cli, go, template
- Language: Go
- Homepage:
- Size: 141 KB
- Stars: 25
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go CLI Project Template ☄️
Powerful template for Go CLI applications with advanced config management

## Features
- Advanced config management with [viper](https://github.com/spf13/viper) and
useful config commands such as setting config values directly from CLI (like this `config set -k logs.write -v true`),
reading env variables and file-based configuration (either TOML or YAML). Also, configuration is self-documented, type `config info` to show every config field available with description for each.
- Cache & Temp files management with `clear` command
- Polished CLI experience with [cobra](https://github.com/spf13/cobra) + [coloredcobra](https://github.com/ivanpirog/coloredcobra) to make things look pretty
- [Afero](https://github.com/spf13/afero) filesystem for various fs utils, abstractions and in-memory fs for testing.
For example, instead of `os.Remove("file")` use `filesystem.Api().Remove("file")`
- Easy to use path management with `where` package
- Logging to file
- Icons!
- Predefined lipgloss colors
## How to use
Press this shiny green button on top

Then you would probably want to rename go mod name from `github.com/metafates/go-template` to something else.
To do this you could use your IDE refactor features or run [just](https://github.com/casey/just) target.
```shell
just rename github.com/username/repo
```
This will prompt you to type a new name and will replace every occurence of the old go mod name with the new one.
## Further usage
### Changing name of the app
Change the value of the constant `Name` at [app/meta.go](https://github.com/metafates/go-template/blob/main/app/meta.go)
### Changing config file format from TOML from YAML
Change the value of the constant `ConfigFormat` at [config/init.go](https://github.com/metafates/go-template/blob/main/config/init.go)
### Declaring new config fields
Firstly, declare a field key name as a constant inside [key/keys.go](https://github.com/metafates/go-template/blob/main/key/keys.go)
Then put them inside [config/default.go](https://github.com/metafates/go-template/blob/0a71f1da1c51415469067edbfbe4cbb90e06ef13/config/default.go#L8:L23) (take a predefined fields for logging as a reference)
For example
```go
// key/keys.go
const IconType = "icon.type"
```
```go
// config/default.go
{
constant.IconType, // config field key
"emoji", // default value
"What type of icons to use", // description
}
```
### Accessing config fields
For the example above it would be `viper.GetString(key.EmojiType)`. See [viper](https://github.com/spf13/viper) for more information
## Something is not clear?
Please, [open an issue](https://github.com/metafates/go-template/issues/new) so I could document it