Skip to content

feat: show successful resource delete message#212

Merged
dbolson merged 8 commits into
mainfrom
sc-241741/delete-message
Apr 29, 2024
Merged

feat: show successful resource delete message#212
dbolson merged 8 commits into
mainfrom
sc-241741/delete-message

Conversation

@dbolson
Copy link
Copy Markdown
Contributor

@dbolson dbolson commented Apr 25, 2024

We needed to refactor some things to support showing a "Successfully deleted {resource}" message because we don't get a JSON response from API delete requests.

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

Comment thread cmd/flags/create.go Outdated
}

output, err := output.CmdOutputCreate(
output, err := output.CmdOutputCreateResource(
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.

The API has one less param now.

Comment thread internal/output/resource_output.go Outdated

// CmdOutputCreateResource returns a response from a resource create action formatted based on the
// output flag.
func CmdOutputCreateResource(outputKind string, input []byte) (string, 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.

The create and update versions are very similar but delete is different.

Copy link
Copy Markdown
Contributor Author

@dbolson dbolson left a comment

Choose a reason for hiding this comment

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

I can simplify the output function for error handling in another PR.

Comment thread cmd/environments/get.go
response,
output.SingularPlaintextOutputFn,
)
output, err := output.CmdOutput("get", viper.GetString(cliflags.OutputFlag), response)
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.

We need to know if the plaintext output should include a success message, so we pass in this value.

return nil, errors.NewLDAPIError(err)
}
memberJson, err := json.Marshal(members.Items)
membersJson, err := json.Marshal(members)
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.

Updated this for consistency with other responses for multiple resources.

Comment thread internal/output/output.go

// CmdOutputCreate builds a command response based on the flag the user provided and the shape of
// the input with a successfully created message. The expected shape is a single JSON object.
func CmdOutputCreate(outputKind string, input []byte, fn PlaintextOutputFn) (string, 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.

Removed these to have a single CmdOutput function so it's simpler for dynamic resource commands.

Comment thread internal/output/output.go

// CmdOutputMultiple builds a command response based on the flag the user provided and the shape of
// the input. The expected shape is a list of JSON objects.
func CmdOutputMultiple(outputKind string, input []byte, fn PlaintextOutputFn) (string, 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.

This is now unused.


// CmdOutput returns a response from a resource create action formatted based on the
// output flag along with an optional message based on the action.
func CmdOutput(action string, outputKind string, input []byte) (string, 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.

This is the "do all the things" function.

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