Skip to content

Commit

Permalink
Always hide identical arch column any width
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jan 14, 2023
1 parent 20e7d38 commit 3945c3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 1 addition & 3 deletions pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ func PrintInstances(w io.Writer, instances []*Instance, format string, options *
if !hideType {
columns++ // VMTYPE
}
if width != 0 && (columns+6)*8 > width && !all {
hideArch = len(archs) == 1
}
hideArch = len(archs) == 1 && !all
if !hideArch {
columns++ // ARCH
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/store/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var instance = Instance{
Dir: "dir",
}

var table = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B dir\n"
var table = "NAME STATUS SSH VMTYPE CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 qemu 0 0B 0B dir\n"

// for width 60, everything is hidden
var table60 = "NAME STATUS SSH CPUS MEMORY DISK\n" +
Expand All @@ -28,15 +28,19 @@ var table60 = "NAME STATUS SSH CPUS MEMORY DISK\n" +
var table80 = "NAME STATUS SSH CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 0 0B 0B dir\n"

// for width 100 (or with all), nothing is hidden
var tableAll = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B dir\n"

// for width 80, directory is hidden (if not identical)
var tableTwo = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK\n" +
"foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B\n" +
"bar Stopped 127.0.0.1:0 vz aarch64 0 0B 0B\n"

const separator = string(filepath.Separator)

var tableHome = "NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 qemu x86_64 0 0B 0B ~" + separator + "dir\n"
var tableHome = "NAME STATUS SSH VMTYPE CPUS MEMORY DISK DIR\n" +
"foo Stopped 127.0.0.1:0 qemu 0 0B 0B ~" + separator + "dir\n"

func TestPrintInstanceTable(t *testing.T) {
var buf bytes.Buffer
Expand Down Expand Up @@ -74,7 +78,7 @@ func TestPrintInstanceTableAll(t *testing.T) {
instances := []*Instance{&instance}
options := PrintOptions{IsTerminal: true, TerminalWidth: 40, AllFields: true}
PrintInstances(&buf, instances, "table", &options)
assert.Equal(t, buf.String(), table)
assert.Equal(t, buf.String(), tableAll)
}

func TestPrintInstanceTableTwo(t *testing.T) {
Expand Down

0 comments on commit 3945c3e

Please sign in to comment.