-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement projects endpoints in v4. Add items and delete endpoints for projects. #50
Conversation
cmd.Flags().BoolVar(&f.all, "all", false, "Delete the project and its contents") | ||
cmd.Flags().BoolVar(&f.dependencies, "dependencies", false, "Delete the project and its contents and dependencies. Can only be specified if all is also specified") | ||
cmd.Flags().BoolVarP(&f.noprompt, "no-prompt", "y", false, "Do not prompt for confirmation.") | ||
cmd.MarkFlagsMutuallyExclusive("id", "name") |
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.
Would it make sense to use https://pkg.go.dev/github.com/spf13/cobra#Command.MarkFlagsOneRequired for id and name here as well? Otherwise the block below -
if f.id == "" {
projectID, err := getProjectId(f.name)
if err != nil {
return err
Will result in the error from getProjectId
if both name and ID were not provided: ...check that the specified project exists
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 actually taken care of above in the PreRunE function:
// ensure one of either id or name is specified
if f.apiVersion == apiVersionFlagV4 {
if f.id == "" && f.name == "" {
return errors.New("required flag(s) \"id\" or \"name\" not set")
}
} else {
if f.name == "" {
return errors.New("required flag(s) \"name\" not set")
}
}
It's a bit tricky because we want either one for v4, but it must be "name" for v3. Though I could potentially clean this up to make it a bit nicer.
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.
Hmm....and actually I need to upgrade the cobra package to get access to that function you listed. Maybe I leave this as is for now.
if f.dependencies { | ||
q := request.URL.Query() | ||
q.Add("deleteDependencies", "true") | ||
request.URL.RawQuery = q.Encode() |
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 looks like if --dependencies
is enabled and --all
isn't, this won't work - as the parameter is specific to the delete-all
endpoint
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.
True, but that is gated in the PreRunE function above that ensures that you must pass in --all
in order to use --dependencies
.
if f.dependencies && !f.all {
return errors.New("dependencies can only be specified if all is also specified")
}
cmd/projects_download.go
Outdated
name string | ||
excludeSensitiveInfo bool | ||
suppressFileRename bool | ||
excludeSelectableItems bool |
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.
Should this be excludeAllSelectableItems
? It seems that is what it eventually translates to when making the call
if f.name != "" { | ||
id, err := getProjectId(f.name) | ||
if err != nil { | ||
return err | ||
} | ||
f.id = id |
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.
Similar as above. Can we use https://pkg.go.dev/github.com/spf13/cobra#Command.MarkFlagsOneRequired for name
and id
?
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.
Same answer as above. I can clean this up when we upgrade the version of cobra, but we still need a bit of special handling because of the different api versions.
cmd/projects_items.go
Outdated
func getProjectId(name string) (string, error) { | ||
client := &http.Client{} | ||
|
||
url := "/fmeapiv4/projects" | ||
|
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.
Could this function live in projects.go
instead?
And this just might be my ignorance of Go standard practices, but how would one typically trace function calls back to their source? I haven't noticed an explicit reference, within projects.go
to this file. I presume everything in that main directory (since it exists in the same package cmd
) can reference one another?
If so, is it possible to make the reference to this function "fully-qualified" so-to-speak? Not that it's particularly hard to find -- but it's not obvious.
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.
You are right that any function in the entire package can be seen by any other file in the same pacakge. I don't know if there is a better way to reference the function more explicitly. I typically just do a find all in vscode.
No description provided.