44 "encoding/json"
55 "errors"
66 "fmt"
7+ "reflect"
8+ "strings"
79 "text/tabwriter"
810 "text/template"
911
@@ -13,6 +15,16 @@ import (
1315 "github.com/spf13/cobra"
1416)
1517
18+ func instanceFields () []string {
19+ fields := []string {}
20+ var instance store.Instance
21+ t := reflect .TypeOf (instance )
22+ for i := 0 ; i < t .NumField (); i ++ {
23+ fields = append (fields , t .Field (i ).Name )
24+ }
25+ return fields
26+ }
27+
1628func newListCommand () * cobra.Command {
1729 listCommand := & cobra.Command {
1830 Use : "list" ,
@@ -24,6 +36,7 @@ func newListCommand() *cobra.Command {
2436 }
2537
2638 listCommand .Flags ().StringP ("format" , "f" , "" , "Format the output using the given Go template" )
39+ listCommand .Flags ().Bool ("list-fields" , false , "List fields available for format" )
2740 listCommand .Flags ().Bool ("json" , false , "JSONify output" )
2841 listCommand .Flags ().BoolP ("quiet" , "q" , false , "Only show names" )
2942
@@ -39,11 +52,25 @@ func listAction(cmd *cobra.Command, args []string) error {
3952 if err != nil {
4053 return err
4154 }
55+ listFields , err := cmd .Flags ().GetBool ("list-fields" )
56+ if err != nil {
57+ return err
58+ }
4259 jsonFormat , err := cmd .Flags ().GetBool ("json" )
4360 if err != nil {
4461 return err
4562 }
4663
64+ if goFormat != "" && listFields {
65+ return errors .New ("option --format conflicts with --list-fields" )
66+ }
67+ if jsonFormat && listFields {
68+ return errors .New ("option --json conflicts with --list-fields" )
69+ }
70+ if listFields {
71+ fmt .Println (strings .Join (instanceFields (), "\n " ))
72+ return nil
73+ }
4774 if quiet && jsonFormat {
4875 return errors .New ("option --quiet conflicts with --json" )
4976 }
0 commit comments