toml2cli
is a utility for generator the boilerplate for CLIs in go.
go get github.com/ttacon/toml2cli
# examples/example.toml
[general]
name = "Hello"
description = "Example toml to cli"
generator = "github.com/urfave/cli"
[[command]]
name = "foo"
aliases = [ "f" ]
description = "processes foo"
action = "fooFunc"
[[command.flags]]
name = "lang"
aliases = [ "l" ]
description = "language for processing"
toml2cli -in-file examples/example.toml -out-file examples/urfave-cli-main.go
package main
import (
"log"
"os"
"github.com/urfave/cli"
)
// DO NOT MODIFY: generated by github.com/ttacon/toml2cli
// If you need to make changes, update the toml config and then regenerate
// this file.
func main() {
app := cli.NewApp()
app.Name = "Hello"
app.Usage = "Example toml to cli"
app.Commands = []cli.Command{
cli.Command{
Description: "processes foo",
Name: "foo",
Action: fooFunc,
Aliases: []string{"f"},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
# examples/example-ishell.go
[general]
name = "Hello"
description = "Example toml to cli"
generator = "github.com/abiosoft/ishell"
historyPath = ".config/foo/history"
banner = "Banner text!"
[[command]]
name = "foo"
aliases = [ "f" ]
description = "processes foo"
func = "fooFunc"
[[command.flags]]
name = "lang"
aliases = [ "l" ]
description = "language for processing"
toml2cli -in-file examples/example-ishell.toml -out-file examples/abiosoft-ishell-main.go
package main
import "github.com/abiosoft/ishell"
// DO NOT MODIFY: generated by github.com/ttacon/toml2cli
// If you need to make changes, update the toml config and then regenerate
// this file.
func main() {
shell := ishell.New()
shell.SetHomeHistoryPath(".config/foo/history")
shell.Println("Banner text!")
shell.AddCommand(&ishell.Cmd{
Name: "foo",
Help: "processes foo",
Func: fooFunc,
})
shell.Run()
}
I write a ton of local CLIs in go (both shells and commands), and got super tired of writing them same boilerplate.