Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
terraformHCL = "terraform-hcl"
tableOutput = "table"
tableWideOutput = "table-wide"
oneLine = "one-line"
)

// Filter Flag Constants
Expand Down Expand Up @@ -110,6 +111,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
cliOutputTypes := []string{
tableOutput,
tableWideOutput,
oneLine,
}
resultsOutputFn := outputs.SimpleInstanceTypeOutput

Expand Down Expand Up @@ -267,6 +269,8 @@ func getOutputFn(outputFlag *string, currentFn selector.InstanceTypesOutputFn) s
return selector.InstanceTypesOutputFn(outputs.TableOutputWide)
case tableOutput:
return selector.InstanceTypesOutputFn(outputs.TableOutputShort)
case oneLine:
return selector.InstanceTypesOutputFn(outputs.OneLineOutput)
}
}
return outputFn
Expand Down
12 changes: 12 additions & 0 deletions pkg/selector/outputs/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ func TableOutputWide(instanceTypeInfoSlice []*ec2.InstanceTypeInfo) []string {
w.Flush()
return []string{buf.String()}
}

// OneLineOutput is an output function which prints the instance type names on a single line separated by commas
func OneLineOutput(instanceTypeInfoSlice []*ec2.InstanceTypeInfo) []string {
instanceTypeNames := []string{}
for _, instanceType := range instanceTypeInfoSlice {
instanceTypeNames = append(instanceTypeNames, *instanceType.InstanceType)
}
if len(instanceTypeNames) == 0 {
return []string{}
}
return []string{strings.Join(instanceTypeNames, ",")}
}
13 changes: 13 additions & 0 deletions pkg/selector/outputs/outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,16 @@ func TestTableOutput_MBtoGB(t *testing.T) {
outputStr = strings.Join(instanceTypeOut, "")
h.Assert(t, strings.Contains(outputStr, "15.000"), "table should include 15.000 GB of memory")
}

func TestOneLineOutput(t *testing.T) {
instanceTypes := getInstanceTypes(t, "t3_micro_and_p3_16xl.json")
instanceTypeOut := outputs.OneLineOutput(instanceTypes)
h.Assert(t, len(instanceTypeOut) == 1, "Should always return 1 line")
h.Assert(t, instanceTypeOut[0] == "t3.micro,p3.16xlarge", "Should return both instance types separated by a comma")

instanceTypeOut = outputs.OneLineOutput([]*ec2.InstanceTypeInfo{})
h.Assert(t, len(instanceTypeOut) == 0, "Should return 0 instance types when passed empty slice")

instanceTypeOut = outputs.OneLineOutput(nil)
h.Assert(t, len(instanceTypeOut) == 0, "Should return 0 instance types when passed nil")
}