mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Add Diskattrmap, Scsiattrmap for probed scsi devices
Additional changes - Use ``iota`` for constants - Remove unncessary C header files - ``new-cmd`` now depends on codegangsta cli
This commit is contained in:
3
cmd/new-cmd/.gitignore
vendored
3
cmd/new-cmd/.gitignore
vendored
@@ -1,2 +1 @@
|
||||
templates.go
|
||||
minio-cli
|
||||
new-cmd
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## Introduction
|
||||
|
||||
`minio-cli` is a stub builder for new commands,options on top of [codegangsta/cli](https://github.com/codegangsta/cli),
|
||||
`new-cmd` is a stub builder for new commands,options on top of [codegangsta/cli](https://github.com/codegangsta/cli),
|
||||
|
||||
Idea behind providing a simple tool for rapid prototyping and encouraging new contributors to the project
|
||||
|
||||
@@ -9,17 +9,17 @@ Idea behind providing a simple tool for rapid prototyping and encouraging new co
|
||||
You just need to set its command name and options:
|
||||
|
||||
```bash
|
||||
$ minio-cli -options option1,option2,option3 [command]
|
||||
$ new-cmd --options option1,option2,option3 --usage "This command is best" [commandname]
|
||||
```
|
||||
|
||||
Generates three files namely [command].go, [command]-options.go, [command].md
|
||||
Generates three files [commandname].go, [commandname]-options.go, [commandname].md respectively
|
||||
|
||||
## Example
|
||||
|
||||
If you want to start to building `bucket` command which has options `get`, `put`, `list`:
|
||||
|
||||
```bash
|
||||
$ minio-cli -options get,put,list bucket
|
||||
$ new-cmd --options get,put,list --usage "Bucket operations" bucket
|
||||
$ ls bucket/
|
||||
bucket-options.go bucket.go bucket.md
|
||||
```
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"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/minio-cli/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() {
|
||||
var flOptions, flUsage, flTemplatePath string
|
||||
|
||||
flag.StringVar(&flOptions, "options", "", "Comma-separated list of options to build")
|
||||
flag.StringVar(&flUsage, "usage", "", "A one liner explains the purpose of the cli being built")
|
||||
flag.StringVar(&flTemplatePath, "templatepath", "", "Non standard templates path")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
inputOptions := strings.Split(flOptions, ",")
|
||||
|
||||
commandname := flag.Arg(0)
|
||||
|
||||
if commandname == "" {
|
||||
log.Fatal("command name must not be blank\n")
|
||||
}
|
||||
|
||||
if inputOptions[0] == "" {
|
||||
log.Fatal("-options option1 should be specified with command name")
|
||||
}
|
||||
|
||||
gopath := os.Getenv("GOPATH")
|
||||
|
||||
var mainTemplatePath, optionsTemplatePath, readmeTemplatePath string
|
||||
if flTemplatePath == "" {
|
||||
mainTemplatePath = path.Join(gopath, TEMPLATEREPO, "main.tmpl")
|
||||
optionsTemplatePath = path.Join(gopath, TEMPLATEREPO, "options.tmpl")
|
||||
readmeTemplatePath = path.Join(gopath, TEMPLATEREPO, "README.tmpl")
|
||||
} else {
|
||||
mainTemplatePath = path.Join(flTemplatePath, "main.tmpl")
|
||||
optionsTemplatePath = path.Join(flTemplatePath, "options.tmpl")
|
||||
readmeTemplatePath = path.Join(flTemplatePath, "README.tmpl")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(mainTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(optionsTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(readmeTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var mainTemplate = template.Must(template.ParseFiles(mainTemplatePath))
|
||||
var optionsTemplate = template.Must(template.ParseFiles(optionsTemplatePath))
|
||||
var readmeTemplate = template.Must(template.ParseFiles(readmeTemplatePath))
|
||||
|
||||
err := os.Mkdir(commandname, 0755)
|
||||
utils.Assert(err)
|
||||
|
||||
command := initCommand(commandname, flUsage, inputOptions)
|
||||
|
||||
optionsGo := source{
|
||||
Name: commandname + "-options.go",
|
||||
TempLate: *optionsTemplate,
|
||||
}
|
||||
|
||||
readmeMd := source{
|
||||
Name: commandname + ".md",
|
||||
TempLate: *readmeTemplate,
|
||||
}
|
||||
|
||||
mainGo := source{
|
||||
Name: commandname + ".go",
|
||||
TempLate: *mainTemplate,
|
||||
}
|
||||
|
||||
err = readmeMd.get(commandname, command)
|
||||
utils.Assert(err)
|
||||
|
||||
mainGo.get(commandname, command)
|
||||
utils.Assert(err)
|
||||
|
||||
optionsGo.get(commandname, command)
|
||||
|
||||
err = GoFormat(commandname)
|
||||
utils.Assert(err)
|
||||
}
|
||||
98
cmd/new-cmd/new-cmd-flags.go
Normal file
98
cmd/new-cmd/new-cmd-flags.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkg/utils"
|
||||
)
|
||||
|
||||
func parseInput(c *cli.Context) {
|
||||
var commandName string
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
commandName = c.Args()[0]
|
||||
default:
|
||||
log.Fatal("command name must not be blank\n")
|
||||
}
|
||||
|
||||
var inputOptions []string
|
||||
if c.String("options") != "" {
|
||||
inputOptions = strings.Split(c.String("options"), ",")
|
||||
}
|
||||
|
||||
if inputOptions[0] == "" {
|
||||
log.Fatal("options cannot be empty with a command name")
|
||||
}
|
||||
|
||||
var commandUsage string
|
||||
if c.String("usage") != "" {
|
||||
commandUsage = c.String("usage")
|
||||
}
|
||||
|
||||
var templatePath string
|
||||
if c.String("path") != "" {
|
||||
templatePath = c.String("path")
|
||||
}
|
||||
|
||||
gopath := os.Getenv("GOPATH")
|
||||
|
||||
var mainTemplatePath, optionsTemplatePath, readmeTemplatePath string
|
||||
if templatePath == TEMPLATEREPO {
|
||||
mainTemplatePath = path.Join(gopath, templatePath, "main.tmpl")
|
||||
optionsTemplatePath = path.Join(gopath, templatePath, "options.tmpl")
|
||||
readmeTemplatePath = path.Join(gopath, templatePath, "README.tmpl")
|
||||
} else {
|
||||
mainTemplatePath = path.Join(templatePath, "main.tmpl")
|
||||
optionsTemplatePath = path.Join(templatePath, "options.tmpl")
|
||||
readmeTemplatePath = path.Join(templatePath, "README.tmpl")
|
||||
}
|
||||
if _, err := os.Stat(mainTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(optionsTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(readmeTemplatePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var mainTemplate = template.Must(template.ParseFiles(mainTemplatePath))
|
||||
var optionsTemplate = template.Must(template.ParseFiles(optionsTemplatePath))
|
||||
var readmeTemplate = template.Must(template.ParseFiles(readmeTemplatePath))
|
||||
|
||||
err := os.Mkdir(commandName, 0755)
|
||||
utils.Assert(err)
|
||||
|
||||
command := initCommand(commandName, commandUsage, inputOptions)
|
||||
|
||||
optionsGo := source{
|
||||
Name: commandName + "-options.go",
|
||||
TempLate: *optionsTemplate,
|
||||
}
|
||||
|
||||
readmeMd := source{
|
||||
Name: commandName + ".md",
|
||||
TempLate: *readmeTemplate,
|
||||
}
|
||||
|
||||
mainGo := source{
|
||||
Name: commandName + ".go",
|
||||
TempLate: *mainTemplate,
|
||||
}
|
||||
|
||||
err = readmeMd.get(commandName, command)
|
||||
utils.Assert(err)
|
||||
|
||||
mainGo.get(commandName, command)
|
||||
utils.Assert(err)
|
||||
|
||||
optionsGo.get(commandName, command)
|
||||
|
||||
err = GoFormat(commandName)
|
||||
utils.Assert(err)
|
||||
}
|
||||
102
cmd/new-cmd/new-cmd.go
Normal file
102
cmd/new-cmd/new-cmd.go
Normal file
@@ -0,0 +1,102 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user