Skip to content

Commit ed1d6db

Browse files
committed
add help command-line argument
1 parent 3e4991c commit ed1d6db

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Contributions are welcome! Open a pull request to fix a bug, or open an issue to
2727
cat sample.json | node json-to-go.js
2828
```
2929

30+
- For more options, check the help page
31+
32+
```sh
33+
node json-to-go.js --help
34+
```
35+
3036
### Credits
3137

3238
JSON-to-Go is brought to you by Matt Holt ([mholt6](https://twitter.com/mholt6)).

json-to-go.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,22 @@ if (typeof module != 'undefined') {
524524
process.stdout.write(output.go)
525525
}
526526

527+
function printHelp() {
528+
console.log(`\
529+
Usage: node json-to-go.js [OPTION]... [FILE]
530+
Convert json to go file and prints the result on stdout.
531+
532+
Optional arguments:
533+
--help Print this help page
534+
--all-omitempty Make all fields "omitempty" (Default: false)
535+
--examples Add examples to go struct. Currently only works without flatten. (Default: false)
536+
--flatten Flatten go struct (Default: true)
537+
--typename=NAME Use a specific name for typename (Default: "AutoGenerated")
538+
539+
All arguments can be inverted by specifing "--no-...", for example "--no-examples".
540+
`)
541+
}
542+
527543
process.argv.forEach((val, index) => {
528544
if (index < 2)
529545
return
@@ -559,8 +575,12 @@ if (typeof module != 'undefined') {
559575
case "all-omitempty":
560576
options.allOmitempty = argument.value
561577
break
578+
case "help":
579+
printHelp()
580+
process.exit(0)
562581
default:
563582
console.error(`Unexpected argument ${val} received`)
583+
printHelp()
564584
process.exit(1)
565585
}
566586
})

0 commit comments

Comments
 (0)