Giter VIP home page Giter VIP logo

toml2cli's Introduction

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.

toml2cli's People

Contributors

ttacon avatar

Stargazers

 avatar GAURAV avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.