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
`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
You just need to set its application name and options:
You just need to set its command name and options:
```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
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
$ minio-cli -options get,put,list foo

View File

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