@@ -3,6 +3,7 @@ package list
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
"strings"
7
8
8
9
"github.com/go-errors/errors"
@@ -19,27 +20,39 @@ func Run(ctx context.Context, fsys afero.Fs) error {
19
20
return err
20
21
}
21
22
22
- table := `|ID|NAME|DEFAULT|GIT BRANCH|STATUS|CREATED AT (UTC)|UPDATED AT (UTC)|
23
+ switch utils .OutputFormat .Value {
24
+ case utils .OutputPretty :
25
+ table := `|ID|NAME|DEFAULT|GIT BRANCH|STATUS|CREATED AT (UTC)|UPDATED AT (UTC)|
23
26
|-|-|-|-|-|-|-|
24
27
`
25
- for _ , branch := range branches {
26
- gitBranch := " "
27
- if branch .GitBranch != nil {
28
- gitBranch = * branch .GitBranch
28
+ for _ , branch := range branches {
29
+ gitBranch := " "
30
+ if branch .GitBranch != nil {
31
+ gitBranch = * branch .GitBranch
32
+ }
33
+ table += fmt .Sprintf (
34
+ "|`%s`|`%s`|`%t`|`%s`|`%s`|`%s`|`%s`|\n " ,
35
+ branch .Id ,
36
+ strings .ReplaceAll (branch .Name , "|" , "\\ |" ),
37
+ branch .IsDefault ,
38
+ strings .ReplaceAll (gitBranch , "|" , "\\ |" ),
39
+ branch .Status ,
40
+ utils .FormatTimestamp (branch .CreatedAt ),
41
+ utils .FormatTimestamp (branch .UpdatedAt ),
42
+ )
29
43
}
30
- table += fmt .Sprintf (
31
- "|`%s`|`%s`|`%t`|`%s`|`%s`|`%s`|`%s`|\n " ,
32
- branch .Id ,
33
- strings .ReplaceAll (branch .Name , "|" , "\\ |" ),
34
- branch .IsDefault ,
35
- strings .ReplaceAll (gitBranch , "|" , "\\ |" ),
36
- branch .Status ,
37
- utils .FormatTimestamp (branch .CreatedAt ),
38
- utils .FormatTimestamp (branch .UpdatedAt ),
39
- )
44
+ return list .RenderTable (table )
45
+ case utils .OutputToml :
46
+ return utils .EncodeOutput (utils .OutputFormat .Value , os .Stdout , struct {
47
+ Branches []api.BranchResponse `toml:"branches"`
48
+ }{
49
+ Branches : branches ,
50
+ })
51
+ case utils .OutputEnv :
52
+ return errors .Errorf ("--output env flag is not supported" )
40
53
}
41
54
42
- return list . RenderTable ( table )
55
+ return utils . EncodeOutput ( utils . OutputFormat . Value , os . Stdout , branches )
43
56
}
44
57
45
58
type BranchFilter func (api.BranchResponse ) bool
0 commit comments