Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #10 from adfinis-sygroup/feat/show_format
Browse files Browse the repository at this point in the history
Added whitespace padded representation of `show` subcommand
  • Loading branch information
winpat authored Jan 25, 2017
2 parents d60b468 + 3521c00 commit 5785c1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ func (c *ShowCommand) Run(args []string) int {
return 1
}

// Get length of the largest key in order to calculate the
// "whitespace padded" representation of `show`
max_key_len := 0
for k, _ := range secret.Data {
if key_len := len(k); key_len > max_key_len {
max_key_len = key_len
}
}

// Add an additional X whitespaces between "key:" and "value"
max_key_len += 4

for k, v := range secret.Data {
c.Ui.Output(fmt.Sprintf("%v: %v", k, v))
c.Ui.Output(fmt.Sprintf("%-"+fmt.Sprint(max_key_len)+"v %v", fmt.Sprint(k, ":"), v))
}

return 0
Expand Down
2 changes: 1 addition & 1 deletion src/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestShow(t *testing.T) {
t.Fatalf("expected error:\n%s\n\nto include: %q", actual, expectedErr)
}

expectedOutput := "key: value"
expectedOutput := "key: value"
if actual := ui.OutputWriter.String(); !strings.Contains(actual, expectedOutput) {
t.Fatalf("expected output:\n%s\n\nto include: %q", actual, expectedOutput)
}
Expand Down

0 comments on commit 5785c1a

Please sign in to comment.