not really known
Find a file
Alexander Kiryukhin d01c3e8f70
Update README.md
2021-04-05 23:40:16 +03:00
example Initial 2021-04-05 23:31:50 +03:00
app.go Initial 2021-04-05 23:31:50 +03:00
command.go Initial 2021-04-05 23:31:50 +03:00
go.mod Initial 2021-04-05 23:31:50 +03:00
LICENSE Initial commit 2021-04-05 23:03:06 +03:00
README.md Update README.md 2021-04-05 23:40:16 +03:00

app

Go Reference

Simple cli applications runner.

Usage

Commands must implements app.Command interface:

type exampleCommand struct {
	test string
}

func (c *exampleCommand) Name() string {
	return "example"
}

func (c *exampleCommand) Usage() string {
	return "just example command"
}

func (c *exampleCommand) Flags() *flag.FlagSet {
	fs := flag.NewFlagSet(c.Name(), flag.ExitOnError)
	fs.StringVar(&c.test, "test", "value", "test flag")
	return fs
}

func (c *exampleCommand) Run(args []string) error {
	fmt.Printf("Runned %s command with flag -test=%s and args: %v", c.Name(), c.test, args)
	return nil
}

Main file example:

package main

import "github.com/neonxp/app"

func main() {
    app := app.New([]app.Command{
        exampleCommand{}, // <- Register command
    })
	if err := app.Start(os.Args); err != nil { // <- Run!
		fmt.Println(err)
		os.Exit(1)
	}
}

That's all!

Full example