Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
haim-kermany committed Jan 10, 2024
1 parent fbe5f6a commit 67a5852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 11 additions & 13 deletions cmd/analyzer/parse_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"slices"
"strings"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ var supportedOutputFormatsMap = map[string]bool{
// supportedAnalysisTypesMap is a map from analysis type to its list of supported output formats
var supportedAnalysisTypesMap = map[string][]string{
allEndpoints: {TEXTFormat, MDFormat, JSONFormat, DRAWIOFormat, ARCHDRAWIOFormat, DEBUGFormat},
allSubnets: {TEXTFormat, JSONFormat},
allSubnets: {TEXTFormat, JSONFormat, DRAWIOFormat, ARCHDRAWIOFormat},
singleSubnet: {TEXTFormat},
allEndpointsDiff: {TEXTFormat, MDFormat},
allSubnetsDiff: {TEXTFormat, MDFormat},
Expand Down Expand Up @@ -189,11 +190,18 @@ func errorInErgs(args *InArgs, flagset *flag.FlagSet) error {
}
if _, ok := supportedAnalysisTypesMap[*args.AnalysisType]; !ok {
flagset.PrintDefaults()
return fmt.Errorf("wrong analysis type %s; must be one of: %s", *args.AnalysisType, strings.Join(supportedAnalysisTypesList, separator))
return fmt.Errorf("wrong analysis type '%s'; must be one of: '%s'",
*args.AnalysisType, strings.Join(supportedAnalysisTypesList, separator))
}
if !supportedOutputFormatsMap[*args.OutputFormat] {
flagset.PrintDefaults()
return fmt.Errorf("wrong output format %s; must be one of: %s", *args.OutputFormat, strings.Join(supportedOutputFormatsList, separator))
return fmt.Errorf("wrong output format '%s'; must be one of: '%s'",
*args.OutputFormat, strings.Join(supportedOutputFormatsList, separator))
}
if !slices.Contains(supportedAnalysisTypesMap[*args.AnalysisType], *args.OutputFormat) {
flagset.PrintDefaults()
return fmt.Errorf("wrong output format '%s' for analysis type '%s'; must be one of: %s",
*args.OutputFormat, *args.AnalysisType, strings.Join(supportedAnalysisTypesMap[*args.AnalysisType], separator))
}
if *args.OutputFormat == DEBUGFormat && *args.AnalysisType != allEndpoints {
return fmt.Errorf("output format %s supported on for %s", DEBUGFormat, allEndpoints)
Expand All @@ -213,16 +221,6 @@ func errorInErgs(args *InArgs, flagset *flag.FlagSet) error {
//gocyclo:ignore
func notSupportedYetArgs(args *InArgs) error {
diffAnalysis := *args.AnalysisType == allEndpointsDiff || *args.AnalysisType == allSubnetsDiff
if *args.OutputFormat == DRAWIOFormat || *args.OutputFormat == ARCHDRAWIOFormat {
if *args.AnalysisType != allEndpoints && *args.AnalysisType != allSubnets {
return fmt.Errorf("drawio output format is not supported with %s analysis type", *args.AnalysisType)
}
return nil
}
if !diffAnalysis && *args.AnalysisType != allEndpoints && *args.OutputFormat != TEXTFormat &&
*args.OutputFormat != JSONFormat {
return fmt.Errorf("currently only txt/json output format supported with %s analysis type", *args.AnalysisType)
}
if diffAnalysis && *args.OutputFormat != TEXTFormat && *args.OutputFormat != MDFormat {
return fmt.Errorf("currently only txt/md output format supported with %s analysis type", *args.AnalysisType)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/vpcmodel/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type SingleAnalysisOutput struct {
format OutFormat
}

// Generate returns SingleAnalysisOutput for its VPC analysis results
// Generate returns a string representing the analysis output for all input VPCs
func (o *OutputGenerator) Generate(f OutFormat, outFile string) (string, error) {
var formatter OutputFormatter
switch f {
Expand Down Expand Up @@ -143,8 +143,8 @@ type OutputFormatter interface {
// serialOutputFormatter is the formatter for json, md and txt formats.
// serialOutputFormatter implements the interface OutputFormatter.
// the main flow of WriteOutput() of serialOutputFormatter is:
// 1. for each vpc, create and use a SingleVpcOutputFormatter to create a VPCsubnetConnectivity,
// 2. aggregate the VPCsubnetConnectivity to one output
// 1. for each vpc, create and use a SingleVpcOutputFormatter to create a SingleAnalysisOutput ,
// 2. aggregate the SingleAnalysisOutputs to one output
type serialOutputFormatter struct {
outFormat OutFormat
}
Expand Down

0 comments on commit 67a5852

Please sign in to comment.