Skip to content

Commit

Permalink
Display help message (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasadG193 authored Jul 26, 2019
1 parent a608918 commit 3978252
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ type Yaml2Go struct {

## Usage

#### Show help

```bash
yaml2go --help
yaml2go converts YAML specs to Go type definitions

Usage:
yaml2go < /path/to/yamlspec.yaml

Examples:
yaml2go < test/example1.yaml
yaml2go < test/example1.yaml > example1.go
```

#### Convert yaml spec to Go struct

```bash
$ yaml2go < example.yaml
```
Expand Down
25 changes: 25 additions & 0 deletions yaml2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import (
"strings"
)

const helpMsg = `yaml2go converts YAML specs to Go type definitions
Usage:
yaml2go < /path/to/yamlspec.yaml
Examples:
yaml2go < test/example1.yaml
yaml2go < test/example1.yaml > example1.go
`

// Yaml2Go to store converted result
type Yaml2Go struct {
Result string
Expand All @@ -21,7 +31,22 @@ func (yg *Yaml2Go) AppendResult(line string) {
yg.Result += line
}

func printHelp(f string) {
helpArgs := []string{"-h", "--help", "help"}
for _, m := range helpArgs {
if f == m {
fmt.Println(helpMsg)
os.Exit(0)
}
}
}

func main() {
// Read args
if len(os.Args) > 1 {
printHelp(os.Args[1])
}

// Read input from the console
var data string
scanner := bufio.NewScanner(os.Stdin)
Expand Down

0 comments on commit 3978252

Please sign in to comment.