subcmds

command
v0.0.0-...-bc19bdb Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2016 License: MIT, MIT Imports: 2 Imported by: 0

README

subcmds example

<tmpl,code=go:cat subcmds.go>

package main

import (
	"fmt"

	"github.com/jpillora/opts"
)

type FooConfig struct {
	Ping string
	Pong string
}

//config
type Config struct {
	Cmd string `type:"cmdname"`
	//subcommand (external struct)
	Foo FooConfig
	//subcommand (inline struct)
	Bar struct {
		Zip string
		Zap string
	}
}

func main() {

	c := Config{}

	opts.Parse(&c)

	fmt.Println(c.Cmd)
	fmt.Println(c.Bar.Zip)
	fmt.Println(c.Bar.Zap)
}
``` $ subcmds bar --zip hello --zap world ``` ``` plain bar hello world ``` ``` $ subcmds --help ``` ``` plain

Usage: subcmds [options]

Options: --help, -h

Subcommands:

  • foo
  • bar
</tmpl>

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