Skip to content

Commit 55e1aca

Browse files
committed
update cli flags + readme
Signed-off-by: adisos <adisos@il.ibm.com>
1 parent e57c857 commit 55e1aca

File tree

8 files changed

+94
-93
lines changed

8 files changed

+94
-93
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ Run the `vpcanalyzer` CLI tool with one of the following commands.
1212

1313
### Global options
1414
```
15-
--dump-resources string file path to store resources collected from the cloud provider
16-
-o, --format string output format; must be one of [json, txt, md, drawio, arch_drawio, svg, arch_svg, html, arch_html, debug]
17-
-h, --help help for vpcanalyzer
18-
--output-file string file path to store results
19-
-p, --provider string collect resources from an account in this cloud provider
20-
-q, --quiet runs quietly, reports only severe errors and results
21-
-r, --region stringArray cloud region from which to collect resources, can pass multiple regions
22-
--resource-group string resource group id or name from which to collect resources
23-
-v, --verbose runs with more informative messages printed to log
24-
--vpc string CRN of the VPC to analyze
25-
-c, --vpc-config stringArray file paths to input configs, can pass multiple config files
15+
-c, --config stringArray config; file paths to input VPC configs, can pass multiple config files
16+
--dump-resources string file path to store resources collected from the cloud provider
17+
-f, --filename string file path to store results
18+
-h, --help help for vpcanalyzer
19+
-o, --output string output format; must be one of [json, txt, md, drawio, arch_drawio, svg, arch_svg, html, arch_html, debug]
20+
-p, --provider string collect resources from an account in this cloud provider
21+
-q, --quiet runs quietly, reports only severe errors and results
22+
-r, --region stringArray cloud region from which to collect resources, can pass multiple regions
23+
--resource-group string resource group id or name from which to collect resources
24+
-v, --verbose runs with more informative messages printed to log
25+
--version version for vpcanalyzer
26+
--vpc string CRN of the VPC to analyze
2627
```
2728

2829
### Providing VPC configuration
29-
VPC configuration should be provided, using the `--vpc-config` option, as a `JSON` file produced by the [`cloud-resource-collector`](https://github.com/np-guard/cloud-resource-collector). Alternatively, VPC configuration can be read directly from a given account using the `--provider` flag.
30+
VPC configuration should be provided, using the `--config` option, as a `JSON` file produced by the [`cloud-resource-collector`](https://github.com/np-guard/cloud-resource-collector). Alternatively, VPC configuration can be read directly from a given account using the `--provider` flag.
3031

3132
### Output formats
32-
Output format is set using the `--format` flag. The following formats are available for the `vpcanalyzer report` command. Other commands may not support all formats.
33+
Output format is set using the `--output` flag. The following formats are available for the `vpcanalyzer report` command. Other commands may not support all formats.
3334
* `txt` - a human readable text output
3435
* `json` - a machine readable JSON output
3536
* `md` - markdown format
@@ -43,7 +44,7 @@ their connectivity at the bottom of the page.
4344
* `arch_html` - an html page showing only the VPC elements
4445
* `debug` - a human readable text format with more details than `txt`
4546

46-
Output can be saved to a file using the `--output-file` flag.
47+
Output can be saved to a file using the `--filename` flag.
4748

4849
## Build the project
4950

cmd/analyzer/main_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,134 +27,134 @@ func TestMain(t *testing.T) {
2727
}{
2828
{
2929
name: "drawio_multi_vpc_all_subnets",
30-
args: "report subnets --output-file multi_vpc.drawio --vpc-config ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o drawio",
30+
args: "report subnets -f multi_vpc.drawio --config ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o drawio",
3131
},
3232
{
3333
name: "drawio_multi_vpc_all_subnets_grouped",
34-
args: "report subnets --output-file multi_vpc_grouped.drawio -c ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o=drawio --grouping",
34+
args: "report subnets -f multi_vpc_grouped.drawio -c ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o=drawio --grouping",
3535
},
3636
{
3737
name: "txt_multi_vpc",
38-
args: "report subnets --output-file multi_vpc.txt --vpc-config ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -otxt",
38+
args: "report subnets -f multi_vpc.txt --config ../../pkg/ibmvpc/examples/input/input_multiple_vpcs.json -o txt",
3939
},
4040

4141
// diff analysis_type
4242
{
4343
name: "txt_diff_acl_testing5",
44-
args: "diff subnets --output-file acl_testing5_diff.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --vpc-config-second ../../pkg/ibmvpc/examples/input/input_acl_testing5_2nd.json --format txt",
44+
args: "diff subnets -f acl_testing5_diff.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --config-second ../../pkg/ibmvpc/examples/input/input_acl_testing5_2nd.json -o txt",
4545
},
4646
{
4747
name: "txt_diff_acl_testing3",
48-
args: "diff endpoints --output-file acl_testing3_diff.txt --vpc-config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --vpc-config-second ../../pkg/ibmvpc/examples/input/input_acl_testing3_2nd.json --format txt",
48+
args: "diff endpoints -f acl_testing3_diff.txt --config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --config-second ../../pkg/ibmvpc/examples/input/input_acl_testing3_2nd.json -o txt",
4949
},
5050
{
5151
name: "md_diff_acl_testing5",
52-
args: "diff subnets --output-file acl_testing5_diff.md --vpc-config ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --vpc-config-second ../../pkg/ibmvpc/examples/input/input_acl_testing5_2nd.json --format md",
52+
args: "diff subnets -f acl_testing5_diff.md --config ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --config-second ../../pkg/ibmvpc/examples/input/input_acl_testing5_2nd.json -o md",
5353
},
5454
{
5555
name: "md_diff_acl_testing3",
56-
args: "diff endpoints --output-file acl_testing3_diff.md --vpc-config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --vpc-config-second ../../pkg/ibmvpc/examples/input/input_acl_testing3_2nd.json --format md",
56+
args: "diff endpoints -f acl_testing3_diff.md --config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --config-second ../../pkg/ibmvpc/examples/input/input_acl_testing3_2nd.json -o md",
5757
},
5858

5959
// all_subnets analysis_type
6060
{
6161
name: "txt_all_subnets_342",
62-
args: "report subnets --output-file 342_all_subnets.txt -c ../../pkg/ibmvpc/examples/input/input_obj_from_issue_342.json --format txt",
62+
args: "report subnets -f 342_all_subnets.txt -c ../../pkg/ibmvpc/examples/input/input_obj_from_issue_342.json -o txt",
6363
},
6464
{
6565
name: "txt_all_subnets_acl_testing5",
66-
args: "report subnets --output-file acl_testing5_all_subnets.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format txt",
66+
args: "report subnets -f acl_testing5_all_subnets.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o txt",
6767
},
6868
{
6969
name: "md_all_subnets_acl_testing5",
70-
args: "report subnets --output-file acl_testing5_all_subnets.md -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format md",
70+
args: "report subnets -f acl_testing5_all_subnets.md -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o md",
7171
},
7272
{
7373
name: "json_all_subnets_acl_testing5",
74-
args: "report subnets --output-file acl_testing5_all_subnets.json -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format json",
74+
args: "report subnets -f acl_testing5_all_subnets.json -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o json",
7575
},
7676

7777
// all_endpoints analysis_type
7878
{
7979
name: "txt_all_endpoints_acl_testing5",
80-
args: "report endpoints --output-file acl_testing5_all_endpoints.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format txt",
80+
args: "report endpoints -f acl_testing5_all_endpoints.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o txt",
8181
},
8282
{
8383
name: "md_all_endpoints_acl_testing5",
84-
args: "report endpoints --output-file acl_testing5_all_endpoints.md -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format md",
84+
args: "report endpoints -f acl_testing5_all_endpoints.md -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o md",
8585
},
8686
{
8787
name: "json_all_endpoints_acl_testing5",
88-
args: "report endpoints --output-file acl_testing5_all_endpoints.json -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format json",
88+
args: "report endpoints -f acl_testing5_all_endpoints.json -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o json",
8989
},
9090
{
9191
name: "debug_all_endpoints_acl_testing5",
92-
args: "report endpoints --output-file acl_testing5_all_endpoints.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format debug",
92+
args: "report endpoints -f acl_testing5_all_endpoints.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o debug",
9393
},
9494

9595
// single_subnet analysis_type
9696
{
9797
name: "txt_single_subnet_acl_testing5",
98-
args: "report single-subnet --output-file acl_testing5_single_subnet.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json --format txt",
98+
args: "report single-subnet -f acl_testing5_single_subnet.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing5.json -o txt",
9999
},
100100

101101
// explain_mode analysis_type
102102
{
103103
name: "txt_explain_acl_testing3",
104-
args: "explain --output-file acl_testing3_explain.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --format txt --src 10.240.10.4 --dst vsi2-ky",
104+
args: "explain -f acl_testing3_explain.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json -o txt --src 10.240.10.4 --dst vsi2-ky",
105105
},
106106
{
107107
name: "debug_explain_acl_testing3",
108-
args: "explain --output-file acl_testing3_explain_debug.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --format txt --src vsi2-ky --dst 10.240.10.4",
108+
args: "explain -f acl_testing3_explain_debug.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json -o txt --src vsi2-ky --dst 10.240.10.4",
109109
},
110110
{
111111
name: "txt_explain_acl_testing3_3rd",
112-
args: "explain --output-file acl_testing3_3rd_explain.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3_3rd.json --format txt --src vsi1-ky --dst 161.26.0.0/16 --protocol tcp --src-min-port 5 --src-max-port 4398",
112+
args: "explain -f acl_testing3_3rd_explain.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3_3rd.json -o txt --src vsi1-ky --dst 161.26.0.0/16 --protocol tcp --src-min-port 5 --src-max-port 4398",
113113
},
114114

115115
// specific vpc
116116
{
117117
name: "txt_specific_vpc_acl_testing3_with_two_vpcs",
118-
args: "report endpoints --output-file specific_vpc_acl_testing3_with_two_vpcs.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3_with_two_vpcs.json --format txt --vpc crn:12",
118+
args: "report endpoints -f specific_vpc_acl_testing3_with_two_vpcs.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3_with_two_vpcs.json -o txt --vpc crn:12",
119119
},
120120

121121
// version
122122
{
123123
name: "version",
124-
args: "--output-file version.txt --version",
124+
args: "-f version.txt --version",
125125
},
126126

127127
// resource group and region filter
128128
{
129129
name: "txt_resource_group_filter_multi_resource_groups",
130-
args: "report endpoints --output-file multi_resource_groups_resource_group_filter.txt -c ../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json --format txt --resource-group ola",
130+
args: "report endpoints -f multi_resource_groups_resource_group_filter.txt -c ../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json -o txt --resource-group ola",
131131
},
132132
{
133133
name: "txt_region_filter_multi_regions",
134-
args: "report endpoints --output-file multi_regions_region_filter.txt -c ../../pkg/ibmvpc/examples/input/input_multi_regions.json --format txt --region us-east",
134+
args: "report endpoints -f multi_regions_region_filter.txt -c ../../pkg/ibmvpc/examples/input/input_multi_regions.json -o txt --region us-east",
135135
},
136136
// multi vpc configs input
137137
{
138138
name: "multi_vpc_configs",
139-
args: "report endpoints --output-file multi_vpc_configs.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json -c ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
139+
args: "report endpoints -f multi_vpc_configs.txt -c ../../pkg/ibmvpc/examples/input/input_acl_testing3.json -c ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
140140
},
141141
{
142142
name: "diff_with_different_uid",
143-
args: "diff endpoints --quiet --vpc-config ../../pkg/ibmvpc/examples/input/input_sg_testing_default.json --vpc-config-second ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
143+
args: "diff endpoints --quiet --config ../../pkg/ibmvpc/examples/input/input_sg_testing_default.json --config-second ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
144144
},
145145
{
146146
name: "test_routing_cmd",
147-
args: "report routing --vpc-config ../../pkg/ibmvpc/examples/input/input_hub_n_spoke_1.json",
147+
args: "report routing --config ../../pkg/ibmvpc/examples/input/input_hub_n_spoke_1.json",
148148
},
149149

150150
// read from account // need to export api-key first
151151
/*{
152152
name: "read_from_account_mode",
153-
args: "report endpoints --output-file account.txt --provider ibm --resource-group ola",
153+
args: "report endpoints -f account.txt --provider ibm --resource-group ola",
154154
},
155155
{
156156
name: "read_from_account_mode_dump_resources",
157-
args: "report endpoints --output-file account.txt --provider ibm --dump-resources account_resources_file.json",
157+
args: "report endpoints -f account.txt --provider ibm --dump-resources account_resources_file.json",
158158
},*/
159159
}
160160
for _, tt := range tests {
@@ -170,13 +170,13 @@ func TestMain(t *testing.T) {
170170
func TestMainWithExpectedOut(t *testing.T) {
171171
tests := []struct {
172172
name string
173-
args string // must include output-file arg
174-
outFile string // must be as in the command line arg output-file
173+
args string // must include filename arg
174+
outFile string // must be as in the command line arg filename
175175
}{
176176
// multi vpc configs input
177177
{
178178
name: "multi_vpc_configs",
179-
args: "report endpoints --output-file multi_vpc_configs.txt --vpc-config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --vpc-config ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
179+
args: "report endpoints -f multi_vpc_configs.txt --config ../../pkg/ibmvpc/examples/input/input_acl_testing3.json --config ../../pkg/ibmvpc/examples/input/input_sg_testing_3.json",
180180
outFile: "multi_vpc_configs.txt",
181181
},
182182
}
@@ -231,37 +231,37 @@ func TestCommandsFailExecute(t *testing.T) {
231231
}{
232232
{
233233
name: "bad_flag_syntax",
234-
args: []string{"report", "endpoints", "--output-file", "out.txt", "vpc-config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
234+
args: []string{"report", "endpoints", "-f", "out.txt", "config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
235235
expectedErrorContains: "unknown command",
236236
},
237237
{
238238
name: "missing_arg_flag",
239-
args: []string{"report", "endpoints", "--output-file", "out.txt", "--vpc-config"},
239+
args: []string{"report", "endpoints", "-f", "out.txt", "--config"},
240240
expectedErrorContains: "flag needs an argument",
241241
},
242242
{
243243
name: "vpc_config_or_provider_not_specified",
244-
args: []string{"report", "endpoints", "--output-file", "out.txt"},
244+
args: []string{"report", "endpoints", "-f", "out.txt"},
245245
expectedErrorContains: "at least one of the flags in the group",
246246
},
247247
{
248248
name: "wrong_analysis_type_format",
249-
args: []string{"report", "single-subnet", "--vpc-config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json", "--format", "md"},
249+
args: []string{"report", "single-subnet", "--config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json", "-o", "md"},
250250
expectedErrorContains: "output format for single-subnet must be one of [txt]",
251251
},
252252
{
253253
name: "src_and_dst_not_specified_for_explain_mode",
254-
args: []string{"explain", "--vpc-config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
254+
args: []string{"explain", "--config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
255255
expectedErrorContains: "required flag(s) \"src\", \"dst\" not set",
256256
},
257257
{
258258
name: "missing_sec_vpc_config_for_diff_analysis",
259-
args: []string{"diff", "subnets", "--vpc-config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
260-
expectedErrorContains: "required flag(s) \"vpc-config-second\" not set",
259+
args: []string{"diff", "subnets", "--config", "../../pkg/ibmvpc/examples/input/input_multi_resource_groups.json"},
260+
expectedErrorContains: "required flag(s) \"config-second\" not set",
261261
},
262262
{
263263
name: "nacls_split_subnets",
264-
args: []string{"report", "subnets", "--vpc-config", "../../pkg/ibmvpc/examples/input/input_split_subnet.json"},
264+
args: []string{"report", "subnets", "--config", "../../pkg/ibmvpc/examples/input/input_split_subnet.json"},
265265
expectedErrorContains: "partial subnet ranges",
266266
},
267267
}

cmd/analyzer/subcmds/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
1313
)
1414

15-
const secondConfigFlag = "vpc-config-second"
15+
const secondConfigFlag = "config-second"
1616

1717
func NewDiffCommand(args *inArgs) *cobra.Command {
1818
const diffCmd = "diff"

cmd/analyzer/subcmds/root.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import (
2828
)
2929

3030
const (
31-
vpcConfigFlag = "vpc-config"
31+
vpcConfigFlag = "config"
3232
providerFlag = "provider"
3333
regionFlag = "region"
3434
rgFlag = "resource-group"
3535
vpcFlag = "vpc"
3636

37-
outputFileFlag = "output-file"
38-
outputFormatFlag = "format"
37+
outputFileFlag = "filename"
38+
outputFormatFlag = "output"
3939
dumpFlag = "dump-resources"
4040
quietFlag = "quiet"
4141
verboseFlag = "verbose"
@@ -86,7 +86,7 @@ func NewRootCommand() *cobra.Command {
8686
}
8787

8888
rootCmd.PersistentFlags().StringArrayVarP(&args.inputConfigFileList, vpcConfigFlag, "c", nil,
89-
"file paths to input configs, can pass multiple config files")
89+
"config; file paths to input VPC configs, can pass multiple config files")
9090
rootCmd.PersistentFlags().VarP(&args.provider, providerFlag, "p", "collect resources from an account in this cloud provider")
9191
rootCmd.PersistentFlags().StringVar(&args.dumpResources, dumpFlag, "", "file path to store resources collected from the cloud provider")
9292
rootCmd.MarkFlagsOneRequired(vpcConfigFlag, providerFlag)
@@ -98,7 +98,7 @@ func NewRootCommand() *cobra.Command {
9898
rootCmd.PersistentFlags().StringVar(&args.resourceGroup, rgFlag, "", "resource group id or name from which to collect resources")
9999
rootCmd.PersistentFlags().StringVar(&args.vpc, vpcFlag, "", "CRN of the VPC to analyze")
100100

101-
rootCmd.PersistentFlags().StringVar(&args.outputFile, outputFileFlag, "", "file path to store results")
101+
rootCmd.PersistentFlags().StringVarP(&args.outputFile, outputFileFlag, "f", "", "file path to store results")
102102
rootCmd.PersistentFlags().VarP(&args.outputFormat, outputFormatFlag, "o", "output format; "+mustBeOneOf(allFormats))
103103

104104
rootCmd.PersistentFlags().BoolVarP(&args.quiet, quietFlag, "q", false, "runs quietly, reports only severe errors and results")

cmd/analyzer/subcmds/vpcconfigs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func buildConfigs(inArgs *inArgs) (vpcConfigs *vpcmodel.MultipleVPCConfigs, err
167167
// we are in diff mode, checking we have only one config per file:
168168
if len(vpcConfigs.Configs()) != 1 || len(vpcConfigsToCompare.Configs()) != 1 {
169169
return nil, fmt.Errorf("diff command only supports a single configuration " +
170-
"for both -vpc-config and -vpc-config-second")
170+
"for both --config and --config-second")
171171
}
172172
vpcConfigs.SetConfigsToCompare(vpcConfigsToCompare.Configs())
173173
}

0 commit comments

Comments
 (0)