Rename appname to commandname for consistency

This commit is contained in:
Harshavardhana 2014-12-19 00:16:41 -08:00
parent a0b57edabe
commit b0e986c82c
2 changed files with 26 additions and 32 deletions

View File

@ -1,22 +1,22 @@
## Introduction ## Introduction
`minio-cli` is option stub builder for ``minio`` project using [codegangsta/cli](https://github.com/codegangsta/cli), `minio-cli` is cli option stub builder for ``minio`` project on top of [codegangsta/cli](https://github.com/codegangsta/cli),
The idea is to be able to do rapid prototyping and facilitate new contributors to the project Ideal for rapid prototyping and encouraging new contributors to the project
## Usage ## Usage
You just need to set its application name and options: You just need to set its command name and options:
```bash ```bash
$ minio-cli -options option1,option2,option3 [application] $ minio-cli -options option1,option2,option3 [command]
``` ```
Generates three files namely [application].go, [application]-options.go, [application].md Generates three files namely [command].go, [command]-options.go, [application].md
## Example ## Example
If you want to start to building `bucket` application which has subcommands `get`, `put`, `list`: If you want to start to building `bucket` command which has options `get`, `put`, `list`:
```bash ```bash
$ minio-cli -options get,put,list foo $ minio-cli -options get,put,list foo

View File

@ -28,7 +28,7 @@ type option struct {
Functionname string Functionname string
} }
type application struct { type command struct {
Name string Name string
Usage string Usage string
Month string Month string
@ -36,20 +36,20 @@ type application struct {
Options []option Options []option
} }
func (f source) generate(appName string, def application) error { func (f source) get(commandName string, definition command) error {
wr, err := os.Create(path.Join(appName, f.Name)) wr, err := os.Create(path.Join(commandName, f.Name))
if err != nil { if err != nil {
return err return err
} }
defer wr.Close() defer wr.Close()
return f.TempLate.Execute(wr, def) return f.TempLate.Execute(wr, definition)
} }
func initApplication(appname, usage string, inputOptions []string) application { func initCommand(commandname, usage string, inputOptions []string) command {
year, month, _ := time.Now().Date() year, month, _ := time.Now().Date()
return application{ return command{
Name: appname, Name: commandname,
Usage: usage, Usage: usage,
Month: month.String(), Month: month.String(),
Year: year, Year: year,
@ -87,14 +87,14 @@ func main() {
inputOptions := strings.Split(flOptions, ",") inputOptions := strings.Split(flOptions, ",")
appname := flag.Arg(0) commandname := flag.Arg(0)
if appname == "" { if commandname == "" {
log.Fatal("app name must not be blank\n") log.Fatal("command name must not be blank\n")
} }
if inputOptions[0] == "" { if inputOptions[0] == "" {
log.Fatal("-options option1 should be specified with appname") log.Fatal("-options option1 should be specified with command name")
} }
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
@ -124,40 +124,34 @@ func main() {
var optionsTemplate = template.Must(template.ParseFiles(optionsTemplatePath)) var optionsTemplate = template.Must(template.ParseFiles(optionsTemplatePath))
var readmeTemplate = template.Must(template.ParseFiles(readmeTemplatePath)) var readmeTemplate = template.Must(template.ParseFiles(readmeTemplatePath))
if _, err := os.Stat(appname); err == nil { err := os.Mkdir(commandname, 0755)
// if exists, we overwrite by default
err = os.RemoveAll(appname)
utils.Assert(err)
}
err := os.Mkdir(appname, 0755)
utils.Assert(err) utils.Assert(err)
application := initApplication(appname, flUsage, inputOptions) command := initCommand(commandname, flUsage, inputOptions)
optionsGo := source{ optionsGo := source{
Name: appname + "-options.go", Name: commandname + "-options.go",
TempLate: *optionsTemplate, TempLate: *optionsTemplate,
} }
readmeMd := source{ readmeMd := source{
Name: appname + ".md", Name: commandname + ".md",
TempLate: *readmeTemplate, TempLate: *readmeTemplate,
} }
mainGo := source{ mainGo := source{
Name: appname + ".go", Name: commandname + ".go",
TempLate: *mainTemplate, TempLate: *mainTemplate,
} }
err = readmeMd.generate(appname, application) err = readmeMd.get(commandname, command)
utils.Assert(err) utils.Assert(err)
mainGo.generate(appname, application) mainGo.get(commandname, command)
utils.Assert(err) utils.Assert(err)
optionsGo.generate(appname, application) optionsGo.get(commandname, command)
err = GoFormat(appname) err = GoFormat(commandname)
utils.Assert(err) utils.Assert(err)
} }