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

Implement projects endpoints in v4. Add items and delete endpoints for projects. #50

Merged
merged 4 commits into from
Apr 12, 2024

Conversation

garnold54
Copy link
Collaborator

No description provided.

@garnold54 garnold54 requested a review from jkerssens March 29, 2024 00:55
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")
Copy link
Contributor

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

Copy link
Collaborator Author

@garnold54 garnold54 Apr 10, 2024

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.

Copy link
Collaborator Author

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.

Comment on lines +114 to +117
if f.dependencies {
q := request.URL.Query()
q.Add("deleteDependencies", "true")
request.URL.RawQuery = q.Encode()
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 if --dependencies is enabled and --all isn't, this won't work - as the parameter is specific to the delete-all endpoint

Copy link
Collaborator Author

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")
}

name string
excludeSensitiveInfo bool
suppressFileRename bool
excludeSelectableItems bool
Copy link
Contributor

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

Comment on lines +116 to +121
if f.name != "" {
id, err := getProjectId(f.name)
if err != nil {
return err
}
f.id = id
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Comment on lines 103 to 107
func getProjectId(name string) (string, error) {
client := &http.Client{}

url := "/fmeapiv4/projects"

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@garnold54 garnold54 requested a review from jkerssens April 10, 2024 21:08
@garnold54 garnold54 merged commit 9a80e0e into main Apr 12, 2024
4 checks passed
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