| 268 | } |
| 269 | |
| 270 | func listAppsCmd(cli *cli) *cobra.Command { |
| 271 | var inputs struct { |
| 272 | RevealSecrets bool |
| 273 | Number int |
| 274 | } |
| 275 | |
| 276 | cmd := &cobra.Command{ |
| 277 | Use: "list", |
| 278 | Aliases: []string{"ls"}, |
| 279 | Args: cobra.NoArgs, |
| 280 | Short: "List your applications", |
| 281 | Long: "List your existing applications. To create one, run: `auth0 apps create`.", |
| 282 | Example: ` auth0 apps list |
| 283 | auth0 apps ls |
| 284 | auth0 apps list --reveal-secrets |
| 285 | auth0 apps list --reveal-secrets --number 100 |
| 286 | auth0 apps ls -r -n 100 --json |
| 287 | auth0 apps ls -r -n 100 --json-compact |
| 288 | auth0 apps ls --csv`, |
| 289 | RunE: func(cmd *cobra.Command, args []string) error { |
| 290 | if inputs.Number < 1 || inputs.Number > 1000 { |
| 291 | return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") |
| 292 | } |
| 293 | |
| 294 | list, err := getWithPagination( |
| 295 | inputs.Number, |
| 296 | func(opts ...management.RequestOption) (result []interface{}, hasNext bool, err error) { |
| 297 | opts = append(opts, management.Parameter("is_global", "false")) |
| 298 | res, apiErr := cli.api.Client.List(cmd.Context(), opts...) |
| 299 | if apiErr != nil { |
| 300 | return nil, false, apiErr |
| 301 | } |
| 302 | var output []interface{} |
| 303 | for _, client := range res.Clients { |
| 304 | output = append(output, client) |
| 305 | } |
| 306 | return output, res.HasNext(), nil |
| 307 | }) |
| 308 | if err != nil { |
| 309 | return fmt.Errorf("failed to list applications: %w", err) |
| 310 | } |
| 311 | |
| 312 | var typedList []*management.Client |
| 313 | for _, item := range list { |
| 314 | typedList = append(typedList, item.(*management.Client)) |
| 315 | } |
| 316 | |
| 317 | cli.renderer.ApplicationList(typedList, inputs.RevealSecrets) |
| 318 | |
| 319 | return nil |
| 320 | }, |
| 321 | } |
| 322 | |
| 323 | cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") |
| 324 | cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.") |
| 325 | cmd.Flags().BoolVar(&cli.csv, "csv", false, "Output in csv format.") |
| 326 | cmd.MarkFlagsMutuallyExclusive("json", "json-compact", "csv") |
| 327 | |