Conversation
|
This pull request has been linked to Shortcut Story #235696: create command to list existing projects. |
| "u", | ||
| "http://localhost:3000", | ||
| "LaunchDarkly base URI.", | ||
| "accessToken", |
There was a problem hiding this comment.
Alphabetized these.
| func ListProjects(ctx context.Context, client2 Client) ([]byte, error) { | ||
| projects, err := client2.List(ctx) | ||
| if err != nil { | ||
| // 401 - should return unauthorized type error with body(?) |
There was a problem hiding this comment.
I'll follow up with a PR to handle errors.
|
|
||
| type MockClient struct{} | ||
|
|
||
| func (c MockClient) List(ctx context.Context) (*ldapi.Projects, error) { |
There was a problem hiding this comment.
I'll change this once we have better error handling.
| viper.GetString("accessToken"), | ||
| viper.GetString("baseUri"), | ||
| ) | ||
| response, err := projects.ListProjects( |
There was a problem hiding this comment.
By separating the command from the actual call, it makes it simpler to test. I could see not needing to test the command if it's responsibility is only to get the flag values and set up whatever the domain (in this case projects.ListProjects needs.
|
|
||
| func runProjectsGet(cmd *cobra.Command, args []string) error { | ||
| // TODO: handle missing flags | ||
| if viper.GetString("accessToken") == "" { |
There was a problem hiding this comment.
I think cobra has a way to require flags, so I'll look into that instead of doing it this way.
| func NewProjectsCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "projects", | ||
| Short: "Return a list of projects.", | ||
| Long: "Return a list of projects.", | ||
| RunE: runProjectsGet, | ||
| } | ||
|
|
||
| return cmd | ||
| } |
There was a problem hiding this comment.
it looks like we're not defining the list action anywhere? or are we going with the default of omitting the action means a GET equivalent
There was a problem hiding this comment.
Whoops, I forgot to add that. Updated.
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "ld-cli/internal/projects" |
There was a problem hiding this comment.
nit but do we care about imports ordering?
There was a problem hiding this comment.
I fixed this in another PR.
`ldcli projects list` returns list of projects in JSON
Creates
ldcli projects listcommand that returns the list of projects as JSON.