Skip to content

QuickStart

christophberger edited this page Oct 19, 2017 · 1 revision

Quick Start

Import start

import (
    "github.com/christophberger/start"
)

Define a flag

start imports pflag, so you can start right away setting up your POSIX compliant flags:

var ip *int = flag.Int("repeat", "r", 1, "Define how often the message gets printed.")

Define a command

start.Add(&start.Command{
		Name:  "echo",
		Short: "Print a message.",
		Long:  "Prints its arguments as a message to stdout.",
		Flags: []string{"repeat"},
		Cmd:   echo
})

func echo(cmd *start.Command) error {
    args := "no args."
    if len(cmd.Args) > 0 {
        args = cmd.Args
    }
    for ( i := 0; i < *ip; i++) {
        stdio.Println(args)
    }
}

Optionally create a config file

<application>.toml

repeat = 2

Optionally set an environment variable

bash$ export <application>_repeat=3

...and go!

start.Up()

Clone this wiki locally