Skip to content

Commit 32d1864

Browse files
committed
Added terminal width output
1 parent 97ee78b commit 32d1864

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

cmd/api/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewFlags(name string) *Flags {
6060
flags.FlagSet.Usage = func() {}
6161

6262
// Register global flags
63+
flags.String("", "out", "", "Set output (csv,txt,tsv) or filename")
6364
flags.Bool("", "debug", false, "Enable debug logging")
6465
flags.Bool("", "verbose", false, "Enable verbose output")
6566
flags.Duration("", "timeout", 0, "Client timeout")

cmd/api/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78
"os"
89
"path"
910
"syscall"
@@ -45,13 +46,13 @@ func main() {
4546
ctx := mycontext.ContextForSignal(os.Interrupt, syscall.SIGQUIT)
4647

4748
// Run function
48-
if err := Run(ctx, fn, args); err != nil {
49+
if err := Run(ctx, os.Stdout, fn, args); err != nil {
4950
fmt.Fprintln(os.Stderr, err)
5051
os.Exit(-2)
5152
}
5253
}
5354

54-
func Run(ctx context.Context, fn *Fn, args []string) error {
55-
writer := tablewriter.New(os.Stdout, tablewriter.OptOutputText(), tablewriter.OptHeader())
55+
func Run(ctx context.Context, w io.Writer, fn *Fn, args []string) error {
56+
writer := tablewriter.New(w, tablewriter.OptTerminalWidth(w), tablewriter.OptOutputText(), tablewriter.OptHeader())
5657
return fn.Call(ctx, writer, args)
5758
}

pkg/bitwarden/schema/profile.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import (
1818
// TYPES
1919

2020
type Profile struct {
21-
Id string `json:"id,width:36"`
21+
Id string `json:"id" writer:",width:36"`
2222
Name string `json:"name"`
2323
Email string `json:"email"`
24-
EmailVerified bool `json:"emailVerified,width:5,right"`
25-
Key string `json:"key,wrap"`
26-
Premium bool `json:"premium,width:5,right"`
27-
PremiumFromOrganization bool `json:"premiumFromOrganization,width:5,right"`
28-
Culture string `json:"culture,width:5,right"`
29-
TwoFactorEnabled bool `json:"twoFactorEnabled,width:5,right"`
30-
SecurityStamp *string `json:"securityStamp,omitempty,width:5,right"`
31-
ForcePasswordReset bool `json:"forcePasswordReset,width:5,right"`
32-
UsesKeyConnector bool `json:"usesKeyConnector,width:5,right"`
24+
EmailVerified bool `json:"emailVerified" writer:",width:5,right,omitempty"`
25+
Key string `json:"key" writer:",wrap,omitempty"`
26+
Premium bool `json:"premium" writer:",width:5,right,omitempty"`
27+
PremiumFromOrganization bool `json:"premiumFromOrganization" writer:",width:5,right,omitempty"`
28+
Culture string `json:"culture" writer:",width:5,right,omitempty"`
29+
TwoFactorEnabled bool `json:"twoFactorEnabled" writer:",width:5,right,omitempty"`
30+
SecurityStamp *string `json:"securityStamp" writer:",width:5,right,omitempty"`
31+
ForcePasswordReset bool `json:"forcePasswordReset" writer:",width:5,right,omitempty"`
32+
UsesKeyConnector bool `json:"usesKeyConnector" writer:",width:5,right,omitempty"`
3333
Organizations []*Organization `json:"organizations,omitempty"`
34-
Object string `json:"object,width:7,right"`
34+
Object string `json:"object" writer:"-"`
3535
}
3636

3737
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)