mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-12-18 12:06:30 +00:00
main: --file flag can be repeated now
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
fc2975ed32
commit
bdace0aacf
1 changed files with 23 additions and 19 deletions
|
@ -27,7 +27,7 @@ func main() {
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
Usage: "Create a directory hierarchy spec",
|
Usage: "Create a directory hierarchy spec",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "file",
|
Name: "file",
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
Usage: "Directory hierarchy spec to validate",
|
Usage: "Directory hierarchy spec to validate",
|
||||||
|
@ -182,9 +182,9 @@ func mainApp(c *cli.Context) error {
|
||||||
)
|
)
|
||||||
|
|
||||||
// -f <file>
|
// -f <file>
|
||||||
if c.String("file") != "" && !c.Bool("create") {
|
if len(c.StringSlice("file")) > 0 && !c.Bool("create") {
|
||||||
// load the hierarchy, if we're not creating a new spec
|
// load the hierarchy, if we're not creating a new spec
|
||||||
fh, err := os.Open(c.String("file"))
|
fh, err := os.Open(c.StringSlice("file")[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -206,15 +206,18 @@ func mainApp(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.String("result-format") == "json" {
|
if c.String("result-format") == "json" {
|
||||||
|
for _, file := range c.StringSlice("file") {
|
||||||
// if they're asking for json, give it to them
|
// if they're asking for json, give it to them
|
||||||
data := map[string][]mtree.Keyword{c.String("file"): specKeywords}
|
data := map[string][]mtree.Keyword{file: specKeywords}
|
||||||
buf, err := json.MarshalIndent(data, "", " ")
|
buf, err := json.MarshalIndent(data, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(string(buf))
|
fmt.Println(string(buf))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Keywords used in [%s]:\n", c.String("file"))
|
for _, file := range c.StringSlice("file") {
|
||||||
|
fmt.Printf("Keywords used in [%s]:\n", file)
|
||||||
for _, kw := range specKeywords {
|
for _, kw := range specKeywords {
|
||||||
fmt.Printf(" %s", kw)
|
fmt.Printf(" %s", kw)
|
||||||
if _, ok := mtree.KeywordFuncs[kw]; !ok {
|
if _, ok := mtree.KeywordFuncs[kw]; !ok {
|
||||||
|
@ -223,6 +226,7 @@ func mainApp(c *cli.Context) error {
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,8 +342,8 @@ func mainApp(c *cli.Context) error {
|
||||||
// -c
|
// -c
|
||||||
if c.Bool("create") {
|
if c.Bool("create") {
|
||||||
fh := os.Stdout
|
fh := os.Stdout
|
||||||
if c.String("file") != "" {
|
if len(c.StringSlice("file")) > 0 {
|
||||||
fh, err = os.Create(c.String("file"))
|
fh, err = os.Create(c.StringSlice("file")[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue