@@ -12,8 +12,8 @@ import (
1212)
1313
1414func newListCmd (app * App ) * cobra.Command {
15- var asJSON bool
1615 var limit int
16+ var exporter cmdutil.Exporter
1717
1818 listCmd := & cobra.Command {
1919 Use : "list" ,
@@ -24,17 +24,17 @@ func newListCmd(app *App) *cobra.Command {
2424 return cmdutil .FlagErrorf ("invalid limit: %v" , limit )
2525 }
2626
27- return app .List (cmd .Context (), asJSON , limit )
27+ return app .List (cmd .Context (), limit , exporter )
2828 },
2929 }
3030
31- listCmd .Flags ().BoolVar (& asJSON , "json" , false , "Output as JSON" )
3231 listCmd .Flags ().IntVarP (& limit , "limit" , "L" , 30 , "Maximum number of codespaces to list" )
32+ cmdutil .AddJSONFlags (listCmd , & exporter , api .CodespaceFields )
3333
3434 return listCmd
3535}
3636
37- func (a * App ) List (ctx context.Context , asJSON bool , limit int ) error {
37+ func (a * App ) List (ctx context.Context , limit int , exporter cmdutil. Exporter ) error {
3838 a .StartProgressIndicatorWithLabel ("Fetching codespaces" )
3939 codespaces , err := a .apiClient .ListCodespaces (ctx , limit )
4040 a .StopProgressIndicator ()
@@ -47,6 +47,10 @@ func (a *App) List(ctx context.Context, asJSON bool, limit int) error {
4747 }
4848 defer a .io .StopPager ()
4949
50+ if exporter != nil {
51+ return exporter .Write (a .io , codespaces )
52+ }
53+
5054 tp := utils .NewTablePrinter (a .io )
5155 if tp .IsTTY () {
5256 tp .AddField ("NAME" , nil , nil )
0 commit comments