Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc-235696/list projects #20

Merged
merged 9 commits into from
Mar 13, 2024
Merged

sc-235696/list projects #20

merged 9 commits into from
Mar 13, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented Mar 13, 2024

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

Copy link

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

"u",
"http://localhost:3000",
"LaunchDarkly base URI.",
"accessToken",
Copy link
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
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
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
cmd/projects.go Outdated
viper.GetString("accessToken"),
viper.GetString("baseUri"),
)
response, err := projects.ListProjects(
Copy link
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.

cmd/projects.go Outdated

func runProjectsGet(cmd *cobra.Command, args []string) error {
// TODO: handle missing flags
if viper.GetString("accessToken") == "" {
Copy link
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.

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
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
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.

"context"
"errors"
"fmt"
"ld-cli/internal/projects"
Copy link
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
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
1 check passed
@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