Skip to content

Commit

Permalink
Add version option
Browse files Browse the repository at this point in the history
  • Loading branch information
x-color committed May 17, 2021
1 parent 794f7d6 commit 944eb63
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"gopkg.in/yaml.v2"
)

var version string

type resource struct {
ID string
Type string `yaml:"Type,omitempty" json:"Type,omitempty"`
Expand Down Expand Up @@ -88,13 +90,15 @@ func newTemplateValue(filename string, raw cfnTemplate) templateValue {

type argument struct {
output string
version bool
filename string
}

func parseArgs(args []string) (argument, error) {
arg := argument{}
flags := flag.NewFlagSet(args[0], flag.ExitOnError)
flags.StringVar(&arg.output, "o", "", "File name. Write to file instead of stdout")
flags.BoolVar(&arg.version, "v", false, "Show version")
flags.Usage = func() {
fmt.Fprintf(os.Stdout, "cfn-doc is a tool for generating a document of CloudFormation template.\n\n")
fmt.Fprintf(os.Stdout, "Usage: \n")
Expand All @@ -107,6 +111,10 @@ func parseArgs(args []string) (argument, error) {
return argument{}, err
}

if arg.version {
return arg, nil
}

if len(flags.Args()) == 0 {
return argument{}, errors.New("template file name is required")
}
Expand Down Expand Up @@ -150,6 +158,11 @@ func main() {
os.Exit(1)
}

if arg.version {
fmt.Println(version)
return
}

cfn, err := readCFnTemplate(arg.filename)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down

0 comments on commit 944eb63

Please sign in to comment.