| 18 | ) |
| 19 | |
| 20 | func NewCmdAPI(f factory.Factory) *cobra.Command { |
| 21 | cmd := &cobra.Command{ |
| 22 | Use: "api <url>", |
| 23 | Short: "Execute a raw API GET request", |
| 24 | Long: "Execute an authenticated GET request against the Octopus Server API and print the JSON response.", |
| 25 | Example: heredoc.Docf(` |
| 26 | %[1]s api /api |
| 27 | %[1]s api /api/spaces |
| 28 | %[1]s api /api/Spaces-1/projects |
| 29 | `, constants.ExecutableName), |
| 30 | Args: cobra.ExactArgs(1), |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | return apiRun(cmd, f, args[0]) |
| 33 | }, |
| 34 | Annotations: map[string]string{ |
| 35 | annotations.IsCore: "true", |
| 36 | }, |
| 37 | } |
| 38 | |
| 39 | return cmd |
| 40 | } |
| 41 | |
| 42 | func apiRun(cmd *cobra.Command, f factory.Factory, path string) error { |
| 43 | if err := validateAPIPath(path); err != nil { |