99 "github.com/cli/cli/internal/ghinstance"
1010 "github.com/cli/cli/pkg/cmdutil"
1111 "github.com/cli/cli/pkg/iostreams"
12+ "github.com/cli/cli/pkg/text"
1213 "github.com/cli/cli/utils"
1314 "github.com/spf13/cobra"
1415)
@@ -27,6 +28,9 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
2728 HttpClient : f .HttpClient ,
2829 }
2930
31+ var flagPublic bool
32+ var flagSecret bool
33+
3034 cmd := & cobra.Command {
3135 Use : "list" ,
3236 Short : "List your gists" ,
@@ -36,27 +40,23 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
3640 return & cmdutil.FlagError {Err : fmt .Errorf ("invalid limit: %v" , opts .Limit )}
3741 }
3842
39- pub := cmd .Flags ().Changed ("public" )
40- secret := cmd .Flags ().Changed ("secret" )
41-
4243 opts .Visibility = "all"
43- if pub && ! secret {
44- opts .Visibility = "public"
45- } else if secret && ! pub {
44+ if flagSecret {
4645 opts .Visibility = "secret"
46+ } else if flagPublic {
47+ opts .Visibility = "public"
4748 }
4849
4950 if runF != nil {
5051 return runF (opts )
5152 }
52-
5353 return listRun (opts )
5454 },
5555 }
5656
5757 cmd .Flags ().IntVarP (& opts .Limit , "limit" , "L" , 10 , "Maximum number of gists to fetch" )
58- cmd .Flags ().Bool ( "public" , false , "Show only public gists" )
59- cmd .Flags ().Bool ( "secret" , false , "Show only secret gists" )
58+ cmd .Flags ().BoolVar ( & flagPublic , "public" , false , "Show only public gists" )
59+ cmd .Flags ().BoolVar ( & flagSecret , "secret" , false , "Show only secret gists" )
6060
6161 return cmd
6262}
@@ -77,10 +77,7 @@ func listRun(opts *ListOptions) error {
7777 tp := utils .NewTablePrinter (opts .IO )
7878
7979 for _ , gist := range gists {
80- fileCount := 0
81- for range gist .Files {
82- fileCount ++
83- }
80+ fileCount := len (gist .Files )
8481
8582 visibility := "public"
8683 visColor := cs .Green
@@ -99,16 +96,16 @@ func listRun(opts *ListOptions) error {
9996 }
10097 }
10198
99+ gistTime := gist .UpdatedAt .Format (time .RFC3339 )
100+ if tp .IsTTY () {
101+ gistTime = utils .FuzzyAgo (time .Since (gist .UpdatedAt ))
102+ }
103+
102104 tp .AddField (gist .ID , nil , nil )
103- tp .AddField (description , nil , cs .Bold )
105+ tp .AddField (text . ReplaceExcessiveWhitespace ( description ) , nil , cs .Bold )
104106 tp .AddField (utils .Pluralize (fileCount , "file" ), nil , nil )
105107 tp .AddField (visibility , nil , visColor )
106- if tp .IsTTY () {
107- updatedAt := utils .FuzzyAgo (time .Since (gist .UpdatedAt ))
108- tp .AddField (updatedAt , nil , cs .Gray )
109- } else {
110- tp .AddField (gist .UpdatedAt .String (), nil , nil )
111- }
108+ tp .AddField (gistTime , nil , cs .Gray )
112109 tp .EndRow ()
113110 }
114111
0 commit comments