-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: hardcoded resource cmds #203
Conversation
"A team is a group of members in your LaunchDarkly account.", | ||
"A team can have maintainers who are able to add and remove team members. It also can have custom roles assigned to it that allows shared access to those roles for all team members. To learn more, read [Teams](https://docs.launchdarkly.com/home/teams).\n\nThe Teams API allows you to create, read, update, and delete a team.\n\nSeveral of the endpoints in the Teams API require one or more member IDs. The member ID is returned as part of the [List account members](/tag/Account-members#operation/getMembers) response. It is the `_id` field of each element in the `items` array.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just a snippet from the teams tag description, which comes from here
I stripped out the header manually, hoping that the format holds true for the other resources (looking like mayybe it is? Will check with Molly).
|
||
require.NoError(t, err) | ||
s := string(output) | ||
assert.Contains(t, s, "would be making a request to /api/v2/teams here, with args: map[data:map[key:team-key name:Team Name] expand:]\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't mocked out a client yet since we're not actually making any requests. will update this test with a mock client when that's a thing
Use: resourceName, | ||
Short: shortDescription, | ||
Long: longDescription, | ||
//TODO: add tracking here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually not sure if we wanna add tracking when just the resource cmd is run? maybe we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been adding them as PersistentPreRun
. That means they won't run when just the resource command runs. But they'll run when subcommands on the resource run. This is what that looks like on my branch/PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup there's a comment in there - will make sure to add it in there in a subsequent PR!
gen_TeamsResourceCmd := resources.NewResourceCmd( | ||
rootCmd, | ||
"teams", | ||
"A team is a group of members in your LaunchDarkly account.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first sentence from the "Teams" tag description (after the headers).
Our previously established format is "Make requests (list, create, etc.) on {resource name}" - not sure which is better in this context 🤔
@@ -129,6 +134,7 @@ func Execute(analyticsTracker analytics.Tracker, version string) { | |||
FlagsClient: flags.NewClient(version), | |||
MembersClient: members.NewClient(version), | |||
ProjectsClient: projects.NewClient(version), | |||
GenericClient: &http.Client{Timeout: time.Second * 3}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess this isn't required yet but wanted to get feedback on where we'd be passing it in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine until we can remove the other clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great
cmd/resources/resources.go
Outdated
} | ||
} | ||
|
||
fmt.Fprintf(cmd.OutOrStdout(), fmt.Sprintf("would be making a request to %s here, with args: %s\n", op.Path, paramVals)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we can remove the fmt.Sprintf
since Fprintf
acts the same.
cmd/resources/resources.go
Outdated
} | ||
|
||
cmd := &cobra.Command{ | ||
Args: validators.Validate(), // tbd on this validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need different validators depending on the operation, could we add it as a field on OperationData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking this is ok for now? Since we're pretty much just validating the required flags, and our existing validator already does that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense.
@@ -129,6 +134,7 @@ func Execute(analyticsTracker analytics.Tracker, version string) { | |||
FlagsClient: flags.NewClient(version), | |||
MembersClient: members.NewClient(version), | |||
ProjectsClient: projects.NewClient(version), | |||
GenericClient: &http.Client{Timeout: time.Second * 3}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine until we can remove the other clients.
} | ||
|
||
for _, p := range op.Params { | ||
shorthand := fmt.Sprintf(p.Name[0:1]) // todo: how do we handle potential dupes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like a low chance, if it's even possible. "params" comes from here. I duplicated the line and reran the generator, getting this error
Operations must have unique `name` + `in` parameters. Repeats of `in:query` + `name:expand`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i meant duplicate shorthands - e.g. limit
and list
would both be l
(not that list
is a thing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can see if that actually ends up being an issue once we get the rest in there maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's interesting. It looks like it will panic with
panic: unable to redefine 'e' shorthand in "get" flagset: it's already used for "expand" flag
I suppose we could iterate through all the existing flags to check if it's already been set and then set it to something else (e2
?), or we just don't set the shorthand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya or add them to a map and check before adding it. was thinking it could be the first two letters if the one letter was already taken (but even then that's not a guaranteed unique value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e
ex
exp
expa
expan
expand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once PersistentPreRun
is added to NewResourceCmd
it looks good to me.
Adds a hardcoded implementation of the
NewResourceCmd
andNewOperationCmd
functions that we plan to generate in the future.Calling help:
Calling the command w/required flags:
$ go run main.go teams create --data '{"key": "my-team-key", "name": "My Team Name"}' would be making a request to /api/v2/teams here, with args: map[data:map[key:my-team-key name:My Team Name] expand:]