You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
minio/cmd/new-cmd/new-cmd.go

102 lines
1.9 KiB

package main
import (
"os"
"path"
"text/template"
"time"
"github.com/codegangsta/cli"
"github.com/minio-io/minio/pkg/utils"
)
type source struct {
Name string
TempLate template.Template
}
const (
// Relative path from GOPATH default
TEMPLATEREPO = "/src/github.com/minio-io/minio/cmd/new-cmd/templates/"
)
type option struct {
Name string
Definename string
Functionname string
}
type command struct {
Name string
Usage string
Month string
Year int
Options []option
}
func (f source) get(commandName string, definition command) error {
wr, err := os.Create(path.Join(commandName, f.Name))
if err != nil {
return err
}
defer wr.Close()
return f.TempLate.Execute(wr, definition)
}
func initCommand(commandname, usage string, inputOptions []string) command {
year, month, _ := time.Now().Date()
return command{
Name: commandname,
Usage: usage,
Month: month.String(),
Year: year,
Options: initOptions(inputOptions),
}
}
func initOptions(inputOptions []string) []option {
var options []option
if inputOptions[0] == "" {
return options
}
for _, name := range inputOptions {
option := option{
Name: name,
Definename: utils.FirstUpper(name),
Functionname: "do" + utils.FirstUpper(name),
}
options = append(options, option)
}
return options
}
func main() {
app := cli.NewApp()
app.Name = "new-cmd"
app.Usage = "Is a stub builder for new commands, options"
var flags = []cli.Flag{
cli.StringFlag{
Name: "options",
Value: "",
Usage: "Command-separated list of options to build",
},
cli.StringFlag{
Name: "path",
Value: TEMPLATEREPO,
Usage: "Non standard templates path",
},
cli.StringFlag{
Name: "usage",
Value: "",
Usage: "A one liner explaining the new command being built",
},
}
app.Flags = flags
app.Action = parseInput
app.Author = "Minio"
app.Run(os.Args)
}