Skip to content

Commit 823b4fb

Browse files
authored
Merge pull request #20 from Vonage/feat/mongo-new
improve output formatting
2 parents 7978bff + 0163e97 commit 823b4fb

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

vcr/mongo/create/create.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ func runCreate(ctx context.Context, opts *Options) error {
5050
return fmt.Errorf("failed to create database: %w", err)
5151
}
5252
fmt.Fprintf(io.Out, heredoc.Doc(`
53-
%s Database created:
54-
username: %s
55-
password: %s
56-
database: %s
57-
connectionString: %s
53+
%s Database created
54+
%s username: %s
55+
%s password: %s
56+
%s database: %s
57+
%s connectionString: %s
5858
`),
5959
c.SuccessIcon(),
60+
c.Blue(cmdutil.InfoIcon),
6061
result.Username,
62+
c.Blue(cmdutil.InfoIcon),
6163
result.Password,
64+
c.Blue(cmdutil.InfoIcon),
6265
result.Database,
66+
c.Blue(cmdutil.InfoIcon),
6367
result.ConnectionString)
6468
return nil
6569
}

vcr/mongo/create/create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func TestMongoCreate(t *testing.T) {
5050
},
5151
want: want{
5252
stdout: heredoc.Doc(`
53-
✓ Database created:
54-
username: test
55-
password: test
56-
database: TestDB
57-
connectionString: mongodb://test:test@localhost:27017/TestDB
53+
✓ Database created
54+
username: test
55+
password: test
56+
database: TestDB
57+
connectionString: mongodb://test:test@localhost:27017/TestDB
5858
`),
5959
},
6060
},

vcr/mongo/info/info.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@ func runInfo(ctx context.Context, opts *Options) error {
5454
return fmt.Errorf("failed to get database info: %w", err)
5555
}
5656
fmt.Fprintf(io.Out, heredoc.Doc(`
57-
%s Database info:
58-
username: %s
59-
password: %s
60-
database: %s
61-
connectionString: %s
57+
%s Database info
58+
%s username: %s
59+
%s password: %s
60+
%s database: %s
61+
%s connectionString: %s
6262
`),
6363
c.SuccessIcon(),
64+
c.Blue(cmdutil.InfoIcon),
6465
result.Username,
66+
c.Blue(cmdutil.InfoIcon),
6567
result.Password,
68+
c.Blue(cmdutil.InfoIcon),
6669
result.Database,
70+
c.Blue(cmdutil.InfoIcon),
6771
result.ConnectionString)
6872
return nil
6973
}

vcr/mongo/info/info_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func TestMongoInfo(t *testing.T) {
5252
},
5353
want: want{
5454
stdout: heredoc.Doc(`
55-
✓ Database info:
56-
username: test
57-
password: test
58-
database: TestDB
59-
connectionString: mongodb://test:test@localhost:27017/TestDB
55+
✓ Database info
56+
username: test
57+
password: test
58+
database: TestDB
59+
connectionString: mongodb://test:test@localhost:27017/TestDB
6060
`),
6161
},
6262
},

vcr/mongo/list/list.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"vonage-cloud-runtime-cli/pkg/cmdutil"
77

88
"github.com/MakeNowJust/heredoc"
9+
"github.com/cli/cli/v2/utils"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -43,7 +44,7 @@ func runList(ctx context.Context, opts *Options) error {
4344
io := opts.IOStreams()
4445
c := opts.IOStreams().ColorScheme()
4546

46-
spinner := cmdutil.DisplaySpinnerMessageWithHandle(" Creating Database")
47+
spinner := cmdutil.DisplaySpinnerMessageWithHandle(" Listing Databases")
4748
result, err := opts.DeploymentClient().ListMongoDatabases(ctx, opts.Version)
4849
spinner.Stop()
4950
if err != nil {
@@ -55,9 +56,17 @@ func runList(ctx context.Context, opts *Options) error {
5556
return nil
5657
}
5758

58-
fmt.Fprintf(io.Out, "%s Databases:\n", c.SuccessIcon())
59+
//nolint
60+
tp := utils.NewTablePrinter(io)
61+
tp.AddField(c.Bold("Database"), nil, nil)
62+
tp.EndRow()
5963
for _, db := range result {
60-
fmt.Fprintf(io.Out, " - %s\n", db)
64+
tp.AddField(db, nil, nil)
65+
tp.EndRow()
66+
}
67+
68+
if err := tp.Render(); err != nil {
69+
return fmt.Errorf("error rending databases: %w", err)
6170
}
6271

6372
return nil

vcr/mongo/list/list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ func TestMongoList(t *testing.T) {
4747
},
4848
want: want{
4949
stdout: heredoc.Doc(`
50-
✓ Databases:
51-
- TestDB1
52-
- TestDB2
50+
Database
51+
TestDB1
52+
TestDB2
5353
`),
5454
},
5555
},

0 commit comments

Comments
 (0)