awslabs / diagram-as-code

Diagram-as-code for AWS architecture.
Apache License 2.0
406 stars 23 forks source link

fix: Remove order dependency for command line options #31

Closed a2ush closed 2 months ago

a2ush commented 2 months ago

Issue #, if available:

Previously, when you did not set an option (e.g. -v or -o filename) before specifying the input file, these option did not appear to work.

[Ex - work well]
$ awsdac -v -o custom-output.png examples/privatelink.yaml 
INFO[0000] input file: examples/privatelink.yaml        
...                                      
INFO[0001] Link Drawing                                 
INFO[0001]                                              
INFO[0001]                                              
INFO[0001] Save custom-output.png 
[Ex - something wrong]
$ awsdac -v examples/privatelink.yaml -o custom-output.png
...
INFO[0001] Save output.png    <----- here is the default filename ("custom-output.png" is not used)

$ awsdac examples/privatelink.yaml -o custom-output.png -v
$                    <----- No debug log

Description of changes:

I try to use spf13/cobra package to handle command line options; it helps options can now be specified in any order.

$ ./awsdac -v ../../examples/privatelink.yaml -o custom-output-test.png
INFO[0000] input file: ../../examples/privatelink.yaml 
...
INFO[0001]                                              
INFO[0001] Save custom-output-test.png  

 ./awsdac ../../examples/privatelink.yaml -o custom-output-test.png -v
INFO[0000] input file: ../../examples/privatelink.yaml
...
INFO[0001]                                              
INFO[0001] Save custom-output-test.png  

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.