-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
CLI: Rework to use RunE
#1935
Labels
Comments
@sarabala1979 did you raise a more general ticket for testing the CLI. |
alexec
added
area/cli
The `argo` CLI
type/tech-debt
and removed
type/feature
Feature request
labels
Feb 7, 2022
This comment was marked as resolved.
This comment was marked as resolved.
MasonM
added a commit
to MasonM/argo-workflows
that referenced
this issue
Sep 24, 2024
It's tricky to write unit tests for the CLI code for three main reasons: exiting on errors, lack of dependency injection, and insufficient mocks. argoproj#3917 tried to solve all of these issues, but appears to have been abandoned. I thought about trying to revive that PR, but it's been over 4 years and there's certainly going to be a ton of conflicts. I figure it's better to take a more focused, incremental approach. This PR is focused on improving error handling in the following ways: 1. Do argument validation using [cobra validators](https://cobra.dev/#positional-and-custom-arguments) instead of custom logic in the `Run` function. Besides being simpler, this leads to better error messages. 2. Replace all `Run` functions with `RunE`, which allows returning errors. This is the same approach that Argo Rollouts is taking (example: https://github.com/argoproj/argo-rollouts/blob/00e39b114849010dd96221a8db441d58e860d4d0/pkg/kubectl-argo-rollouts/cmd/abort/abort.go#L41) 3. Replace nearly all calls to `log.Fatal()`/`errors.CheckError()`/etc with error propagation. Signed-off-by: Mason Malone <mmalone@adobe.com>
MasonM
added a commit
to MasonM/argo-workflows
that referenced
this issue
Sep 24, 2024
It's tricky to write unit tests for the CLI code for three main reasons: exiting on errors, lack of dependency injection, and insufficient mocks. argoproj#3917 tried to solve all of these issues, but appears to have been abandoned. I thought about trying to revive that PR, but it's been over 4 years and there's certainly going to be a ton of conflicts. I figure it's better to take a more focused, incremental approach. This PR is focused on improving error handling in the following ways: 1. Do argument validation using [cobra validators](https://cobra.dev/#positional-and-custom-arguments) instead of custom logic in the `Run` function. Besides being simpler, this leads to better error messages. 2. Replace all `Run` functions with `RunE`, which allows returning errors. This is the same approach that Argo Rollouts is taking (example: https://github.com/argoproj/argo-rollouts/blob/00e39b114849010dd96221a8db441d58e860d4d0/pkg/kubectl-argo-rollouts/cmd/abort/abort.go#L41) 3. Replace nearly all calls to `log.Fatal()`/`errors.CheckError()`/etc with error propagation. Signed-off-by: Mason Malone <mmalone@adobe.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rework the CLI to use
cobra.RunE
instead ofcobra.Run
. This will provide some benefits such as unit testing for CLI commands, ability to export CLI as a package, etc.Follow the model used by Argo Rollouts.
The text was updated successfully, but these errors were encountered: