(f *cmdutil.Factory)
| 114 | } |
| 115 | |
| 116 | func NewOpenCmd(f *cmdutil.Factory) *cobra.Command { |
| 117 | opts := &OpenOptions{ |
| 118 | IO: f.IOStreams, |
| 119 | config: f.Config, |
| 120 | PrintFlags: cmdutil.NewPrintFlags(), |
| 121 | Authenticate: auth.EnsureAuthenticated, |
| 122 | SelectApplication: func() (*dashboard.Application, error) { |
| 123 | return selectapp.Run(f) |
| 124 | }, |
| 125 | NewDashboardClient: func(clientID string) *dashboard.Client { |
| 126 | return dashboard.NewClient(clientID) |
| 127 | }, |
| 128 | Browser: pkgopen.Browser, |
| 129 | } |
| 130 | |
| 131 | cmd := &cobra.Command{ |
| 132 | Use: "open <shortcut>", |
| 133 | ValidArgs: targetNames(), |
| 134 | ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 135 | return targetNames(), cobra.ShellCompDirectiveNoFileComp |
| 136 | }, |
| 137 | Short: "Open Algolia pages in your browser", |
| 138 | Long: heredoc.Doc(` |
| 139 | Open Algolia pages in your browser. |
| 140 | |
| 141 | Resource shortcuts (docs, API reference, status, …) open directly. |
| 142 | |
| 143 | Application pages (dashboard, indices, crawler, connectors, api-keys, |
| 144 | usage, team, billing, cost-management) are scoped to the current |
| 145 | application: they require you to be signed in and prompt you to select |
| 146 | an application if none is configured. |
| 147 | |
| 148 | Run 'algolia open --list' to see every shortcut. |
| 149 | |
| 150 | With an output format (--output), the resolved page links are printed |
| 151 | instead of opening a browser. |
| 152 | `), |
| 153 | Example: heredoc.Doc(` |
| 154 | # List all shortcuts |
| 155 | $ algolia open --list |
| 156 | |
| 157 | # List all shortcuts as JSON |
| 158 | $ algolia open --list --output json |
| 159 | |
| 160 | # Open the documentation home page |
| 161 | $ algolia open docs |
| 162 | |
| 163 | # Open the dashboard for the current application |
| 164 | $ algolia open dashboard |
| 165 | |
| 166 | # Open billing / payment details for the current application |
| 167 | $ algolia open billing |
| 168 | |
| 169 | # Print a page link as JSON instead of opening it |
| 170 | $ algolia open billing --output json |
| 171 | `), |
| 172 | Args: cobra.MaximumNArgs(1), |
| 173 | RunE: func(cmd *cobra.Command, args []string) error { |
no test coverage detected