| 40 | } |
| 41 | |
| 42 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 43 | opts := ListOptions{ |
| 44 | IO: f.IOStreams, |
| 45 | Config: f.Config, |
| 46 | HttpClient: f.HttpClient, |
| 47 | Now: time.Now, |
| 48 | } |
| 49 | |
| 50 | var ( |
| 51 | flagPublic bool |
| 52 | flagPrivate bool |
| 53 | ) |
| 54 | |
| 55 | cmd := &cobra.Command{ |
| 56 | Use: "list [<owner>]", |
| 57 | Args: cobra.MaximumNArgs(1), |
| 58 | Short: "List repositories owned by user or organization", |
| 59 | Long: heredoc.Docf(` |
| 60 | List repositories owned by a user or organization. |
| 61 | |
| 62 | Note that the list will only include repositories owned by the provided argument, |
| 63 | and the %[1]s--fork%[1]s or %[1]s--source%[1]s flags will not traverse ownership boundaries. For example, |
| 64 | when listing the forks in an organization, the output would not include those owned by individual users. |
| 65 | `, "`"), |
| 66 | Aliases: []string{"ls"}, |
| 67 | RunE: func(c *cobra.Command, args []string) error { |
| 68 | if opts.Limit < 1 { |
| 69 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 70 | } |
| 71 | |
| 72 | if err := cmdutil.MutuallyExclusive("specify only one of `--public`, `--private`, or `--visibility`", flagPublic, flagPrivate, opts.Visibility != ""); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | if opts.Source && opts.Fork { |
| 76 | return cmdutil.FlagErrorf("specify only one of `--source` or `--fork`") |
| 77 | } |
| 78 | if opts.Archived && opts.NonArchived { |
| 79 | return cmdutil.FlagErrorf("specify only one of `--archived` or `--no-archived`") |
| 80 | } |
| 81 | |
| 82 | if flagPrivate { |
| 83 | opts.Visibility = "private" |
| 84 | } else if flagPublic { |
| 85 | opts.Visibility = "public" |
| 86 | } |
| 87 | |
| 88 | if len(args) > 0 { |
| 89 | opts.Owner = args[0] |
| 90 | } |
| 91 | |
| 92 | if runF != nil { |
| 93 | return runF(&opts) |
| 94 | } |
| 95 | return listRun(&opts) |
| 96 | }, |
| 97 | } |
| 98 | |
| 99 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of repositories to list") |