cmd: Refactor badge
command into subcommands with shared flags
#525
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHAT
This PR refactors the
badge
command to use dedicated subcommands forcoverage
,ratio
, andtime
instead of handling them with a single switch-case block.Key changes:
badge coverage
,badge ratio
, andbadge time
badge
command to display help by default when no subcommand is provided.Before:
After:
For the subcommands:
go run main.go badge coverage --help
go run main.go badge ratio --help
❯ go run main.go badge ratio --help
generate code to test ratio badge
Usage:
octocov badge ratio [flags]
Flags:
--config string config file path
-h, --help help for ratio
--out string output file path
go run main.go badge time --help
❯ go run main.go badge time --help
generate test execution time badge
Usage:
octocov badge time [flags]
Flags:
--config string config file path
-h, --help help for time
--out string output file path
Tests
I tested this code with the following
.octocov.yml
in both GitHub Actions and the local environment.On Workflow
Please refer to the final workflow in following PR:
All commands and flags are verified in the workflow as follows:
On Local
Case 1: octocov badge coverage
Case 2: octocov badge ratio
Note
octocov badge time
doesn't support the local environment if my understanding is correct.WHY
octocov badge
help message don't show required subcommands #523