https://github.com/hedzr/cmdr-loaders
loaders of the external sources, for cmdr v2
https://github.com/hedzr/cmdr-loaders
configuration-files env hcl2 hjson json nestedtext toml yaml
Last synced: about 2 months ago
JSON representation
loaders of the external sources, for cmdr v2
- Host: GitHub
- URL: https://github.com/hedzr/cmdr-loaders
- Owner: hedzr
- License: apache-2.0
- Created: 2024-04-21T06:53:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-08-03T14:33:38.000Z (3 months ago)
- Last Synced: 2025-08-03T16:22:39.386Z (3 months ago)
- Topics: configuration-files, env, hcl2, hjson, json, nestedtext, toml, yaml
- Language: Go
- Homepage:
- Size: 246 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Loaders for cmdr/v2


[](https://github.com/hedzr/cmdr-loaders/releases)Local configuration file loaders for various file formats, such as YAML, TOML, HCL, and much more.
This is an addon library especially for [cmdr/v2](https://github.com/hedzr/cmdr).
The typical app is [cmdr-test/examples/large](https://github.com/hedzr/cmdr-tests/blob/master/examples/large).

A tiny app using `cmdr/v2` and `cmdr-loaders` is:
```go
package mainimport (
"context"
"os"loaders "github.com/hedzr/cmdr-loaders"
"github.com/hedzr/cmdr/v2"
"github.com/hedzr/cmdr/v2/cli"
"github.com/hedzr/cmdr/v2/examples/common"
"github.com/hedzr/cmdr/v2/examples/blueprint/cmd"
"github.com/hedzr/cmdr/v2/examples/devmode"
"github.com/hedzr/cmdr/v2/pkg/logz"
)const (
appName = "blueprint"
desc = `a good blueprint for you.`
version = cmdr.Version
author = `The Examples Authors`
)func main() {
ctx := context.Background()
app := prepareApp(cmd.Commands...) // define your own commands implementations with cmd/*.go
if err := app.Run(ctx); err != nil {
logz.ErrorContext(ctx, "Application Error:", "err", err) // stacktrace if in debug mode/build
os.Exit(app.SuggestRetCode())
} else if rc := app.SuggestRetCode(); rc != 0 {
os.Exit(rc)
}
}func prepareApp(commands ...cli.CmdAdder) cli.App {
return loaders.Create(
appName, version, author, desc,
append([]cli.Opt{
cmdr.WithAutoEnvBindings(true), // default it's false
cmdr.WithSortInHelpScreen(true), // default it's false
// cmdr.WithDontGroupInHelpScreen(false), // default it's false
// cmdr.WithForceDefaultAction(false),
})...,
).
// importing devmode package and run its init():
With(func(app cli.App) { logz.Debug("in dev mode?", "mode", devmode.InDevelopmentMode()) }).
WithBuilders(
common.AddHeadLikeFlagWithoutCmd, // add a `--line` option, feel free to remove it.
common.AddToggleGroupFlags, //
common.AddTypedFlags, //
common.AddKilobytesFlag, //
common.AddValidArgsFlag, //
).
WithAdders(commands...).
Build()
}
```and `cmd/...` at:
- [cmd/](https://github.com/hedzr/cmdr-tests/blob/master/examples/blueprint/cmd/)
See also:
- [cmdr/v2](https://github.com/hedzr/cmdr)
- [blueprint app - cmdr-tests](https://github.com/hedzr/cmdr-tests/blob/master/examples/blueprint/)## History
See full list in [CHANGELOG](https://github.com/hedzr/cmdr-loaders/blob/master/CHANGELOG)
## License
Apache 2.0