Wiki: easygen cli code-gen example by code
The easygen provides a rich set of options to auto-generating Go code for command line parameter handling. Here are them in real code.
For built-in flag package
Sample Go flag package based code
Sample Go code:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineFlag.ref#L5-L112
Which is generated from this YAML file:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineFlag.yaml#L1-L76
For easygen itself using the built-in flag package
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/cmd/easygen/flags.go#L1-L86
Which is generated from this YAML file:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/cmd/easygen/easygen.yaml#L1-L76
For ffcvt using the built-in flag package
This is by far the longest command line parameter handling code I've ever built --
https://github.com/suntong/ffcvt/blob/master/config.go
and it is built by easygen automatically as well.
For the viper package
Sample Go code:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCV.ref#L2-L18
Which is generated from this YAML file:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCV.yaml#L1-L30
For the cli package
Sample cli package based code 1
Sample Go code:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCLI-024.ref#L1-L144
Which is generated from this YAML file:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCLI-024.yaml#L1-L108
Sample cli package based code 2
Sample Go code 2:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCLI-027.ref#L1-L138
This is my current way of generating cli package based command line parameter handling code.
It is generated from this YAML file:
https://github.com/go-easygen/easygen/blob/cdf80e923cb3ba9dca32b689e2e99de66085d255/test/commandlineCLI-027.yaml#L1-L116