Skip to content

Commit 8d6db63

Browse files
committed
add help command-line argument
1 parent eb44349 commit 8d6db63

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
@@ -523,6 +523,22 @@ if (typeof module != 'undefined') {
523523
process.stdout.write(output.go)
524524
}
525525

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

0 commit comments

Comments
 (0)