toml2cli

command module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2021 License: MIT Imports: 10 Imported by: 0

README

toml2cli

toml2cli is a utility for generator the boilerplate for CLIs in go.

Installation

go get github.com/ttacon/toml2cli

Example usage

github.com/urfave/cli
Config
# 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"
Generate
toml2cli -in-file examples/example.toml -out-file examples/urfave-cli-main.go
Output
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)
	}
}
github.com/abiosoft/ishell
Config
# 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"
Generate
toml2cli -in-file examples/example-ishell.toml -out-file examples/abiosoft-ishell-main.go
Output
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()

}

Why does this exist?

I write a ton of local CLIs in go (both shells and commands), and got super tired of writing them same boilerplate.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL