transform the struct in golang into a cmdline
use the reflect of golang to transform your struct into a cmdline program.
package main
import (
"github.com/WinChua/struct2cmd"
"fmt"
)
type A struct {
comm int
Name string
Time int64
msg string
}
func (a *A) setUp() {
a.comm = 4
}
func (a *A) Hello() {
for i:=0; i< a.comm * int(a.Time); i++ {
fmt.Println(a.Name)
}
a.msg = "Success"
}
func (a *A) showResult() {
fmt.Println(a.msg)
}
func main() {
a := &A{}
a.setUp()
struct2cmd.Run(a)
a.showResult()
}
$ go build
$ ./hmm -h
Usage of ./hmm:
-method string
method should in [Hello]
-name string
Name
By default, the field of your struct will be the flag of the cmdline.
Additionally, an option called "method" will be added which could be used to specify the method name to be call.