Skip to content

Commit

Permalink
Merge pull request casualjim#3 from mkrou/master
Browse files Browse the repository at this point in the history
fix flag issue
  • Loading branch information
casualjim committed Nov 16, 2017
2 parents 9d0f126 + 353b8f3 commit 247a743
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,30 @@ import (
const LoadHTTPTimeout = 30 * time.Second

var (
output string
output string
flagSet = flag.NewFlagSet("", flag.ExitOnError)
)

func init() {
flag.StringVar(&output, "output", "", "Write to the file instead of to stdout")
flagSet.StringVar(&output, "output", "", "Write to the file instead of to stdout")
}

func main() {
flag.Usage = func() {
flagSet.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s [YAML FILE OR URL]\n\n", os.Args[0])
flag.PrintDefaults()
flagSet.PrintDefaults()
}
flag.Parse()

if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "you need to provide the file path or url to load")
os.Exit(1)
}

flagSet.Parse(os.Args[2:])
json, err := YAMLDoc(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

if output == "" {
fmt.Println(string(json))
} else {
Expand Down

0 comments on commit 247a743

Please sign in to comment.