| 74 | } |
| 75 | |
| 76 | func listAppsCmd() *cobra.Command { |
| 77 | return &cobra.Command{ |
| 78 | Use: "list", |
| 79 | Short: "List all applications", |
| 80 | Long: "List all applications which are configured in the configuration file", |
| 81 | Example: heredoc.Doc(` |
| 82 | # List all applications |
| 83 | $ stream-cli config list |
| 84 | `), |
| 85 | RunE: func(cmd *cobra.Command, args []string) error { |
| 86 | w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0) |
| 87 | t := tabby.NewCustom(w) |
| 88 | t.AddHeader("", "Name", "Access Key", "Secret Key", "URL") |
| 89 | |
| 90 | config := cfg.GetConfig(cmd) |
| 91 | |
| 92 | for _, app := range config.Apps { |
| 93 | def := "" |
| 94 | if app.Name == config.Default { |
| 95 | def = "(default)" |
| 96 | } |
| 97 | |
| 98 | secret := fmt.Sprintf("**************%v", app.AccessSecretKey[len(app.AccessSecretKey)-4:]) |
| 99 | t.AddLine(def, app.Name, app.AccessKey, secret, app.ChatURL) |
| 100 | } |
| 101 | t.Print() |
| 102 | return nil |
| 103 | }, |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | func setAppDefaultCmd() *cobra.Command { |
| 108 | return &cobra.Command{ |