Skip to content

sc-235696/list projects#20

Merged
dbolson merged 9 commits intomainfrom
sc-235696/list-projects
Mar 13, 2024
Merged

sc-235696/list projects#20
dbolson merged 9 commits intomainfrom
sc-235696/list-projects

Conversation

@dbolson
Copy link
Copy Markdown
Contributor

@dbolson dbolson commented Mar 13, 2024

Creates ldcli projects list command that returns the list of projects as JSON.

@shortcut-integration
Copy link
Copy Markdown

This pull request has been linked to Shortcut Story #235696: create command to list existing projects.

Comment thread cmd/root.go
"u",
"http://localhost:3000",
"LaunchDarkly base URI.",
"accessToken",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(?)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll follow up with a PR to handle errors.


type MockClient struct{}

func (c MockClient) List(ctx context.Context) (*ldapi.Projects, error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this once we have better error handling.

@dbolson dbolson marked this pull request as ready for review March 13, 2024 16:00
Comment thread cmd/projects.go
viper.GetString("accessToken"),
viper.GetString("baseUri"),
)
response, err := projects.ListProjects(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/projects.go

func runProjectsGet(cmd *cobra.Command, args []string) error {
// TODO: handle missing flags
if viper.GetString("accessToken") == "" {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cobra has a way to require flags, so I'll look into that instead of doing it this way.

Comment thread cmd/projects.go Outdated
Comment on lines +14 to +23
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
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I forgot to add that. Updated.

Comment thread cmd/projects/list.go
"context"
"errors"
"fmt"
"ld-cli/internal/projects"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but do we care about imports ordering?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in another PR.

@dbolson dbolson merged commit 1d502f7 into main Mar 13, 2024
@dbolson dbolson deleted the sc-235696/list-projects branch March 13, 2024 17:59
sunnyguduru pushed a commit that referenced this pull request Mar 13, 2024
`ldcli projects list` returns list of projects in JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants