From dcb03e1fa30b465cce50af161cfe575e75046d8e Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 29 May 2022 13:15:31 +0200 Subject: [PATCH] feat: group flags by categories (#6) --- urfave/build.go | 128 ++++++++++++++++++++++++++-------------------- urfave/calver.go | 8 ++- urfave/commit.go | 13 ++++- urfave/logging.go | 9 ++-- urfave/network.go | 9 ++-- urfave/repo.go | 12 ++++- urfave/semver.go | 10 +++- urfave/stage.go | 15 +++++- urfave/step.go | 4 +- urfave/system.go | 5 +- urfave/urfave.go | 31 +++++++---- 11 files changed, 164 insertions(+), 80 deletions(-) diff --git a/urfave/build.go b/urfave/build.go index d272a84..0d4478d 100644 --- a/urfave/build.go +++ b/urfave/build.go @@ -14,97 +14,115 @@ import ( ) // buildFlags has the cli.Flags for the drone.Build. -func buildFlags() []cli.Flag { +func buildFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ - Name: "build.branch", - Usage: "build branch", - EnvVars: []string{"DRONE_BRANCH"}, + Name: "build.branch", + Usage: "build branch", + EnvVars: []string{"DRONE_BRANCH"}, + Category: category, }, &cli.IntFlag{ - Name: "build.pull-request", - Usage: "build pull request", - EnvVars: []string{"DRONE_PULL_REQUEST"}, + Name: "build.pull-request", + Usage: "build pull request", + EnvVars: []string{"DRONE_PULL_REQUEST"}, + Category: category, }, &cli.StringFlag{ - Name: "build.tag", - Usage: "build tag", - EnvVars: []string{"DRONE_TAG"}, + Name: "build.tag", + Usage: "build tag", + EnvVars: []string{"DRONE_TAG"}, + Category: category, }, &cli.StringFlag{ - Name: "build.source-branch", - Usage: "build source branch", - EnvVars: []string{"DRONE_SOURCE_BRANCH"}, + Name: "build.source-branch", + Usage: "build source branch", + EnvVars: []string{"DRONE_SOURCE_BRANCH"}, + Category: category, }, &cli.StringFlag{ - Name: "build.target-branch", - Usage: "build target branch", - EnvVars: []string{"DRONE_TARGET_BRANCH"}, + Name: "build.target-branch", + Usage: "build target branch", + EnvVars: []string{"DRONE_TARGET_BRANCH"}, + Category: category, }, &cli.IntFlag{ - Name: "build.number", - Usage: "build number", - EnvVars: []string{"DRONE_BUILD_NUMBER"}, + Name: "build.number", + Usage: "build number", + EnvVars: []string{"DRONE_BUILD_NUMBER"}, + Category: category, }, &cli.IntFlag{ - Name: "build.parent", - Usage: "build parent", - EnvVars: []string{"DRONE_BUILD_PARENT"}, + Name: "build.parent", + Usage: "build parent", + EnvVars: []string{"DRONE_BUILD_PARENT"}, + Category: category, }, &cli.StringFlag{ - Name: "build.event", - Usage: "build event", - EnvVars: []string{"DRONE_BUILD_EVENT"}, + Name: "build.event", + Usage: "build event", + EnvVars: []string{"DRONE_BUILD_EVENT"}, + Category: category, }, &cli.StringFlag{ - Name: "build.action", - Usage: "build action", - EnvVars: []string{"DRONE_BUILD_ACTION"}, + Name: "build.action", + Usage: "build action", + EnvVars: []string{"DRONE_BUILD_ACTION"}, + Category: category, }, &cli.StringFlag{ - Name: "build.status", - Usage: "build status", - EnvVars: []string{"DRONE_BUILD_STATUS"}, + Name: "build.status", + Usage: "build status", + EnvVars: []string{"DRONE_BUILD_STATUS"}, + Category: category, }, &cli.StringFlag{ - Name: "build.link", - Usage: "build link", - EnvVars: []string{"DRONE_BUILD_LINK"}, + Name: "build.link", + Usage: "build link", + EnvVars: []string{"DRONE_BUILD_LINK"}, + Category: category, }, &cli.StringFlag{ - Name: "build.created", - Usage: "build created", - EnvVars: []string{"DRONE_BUILD_CREATED"}, + Name: "build.created", + Usage: "build created", + EnvVars: []string{"DRONE_BUILD_CREATED"}, + Category: category, }, &cli.StringFlag{ - Name: "build.started", - Usage: "build started", - EnvVars: []string{"DRONE_BUILD_STARTED"}, + Name: "build.started", + Usage: "build started", + EnvVars: []string{"DRONE_BUILD_STARTED"}, + Category: category, }, &cli.StringFlag{ - Name: "build.finished", - Usage: "build finished", - EnvVars: []string{"DRONE_BUILD_FINISHED"}, + Name: "build.finished", + Usage: "build finished", + EnvVars: []string{"DRONE_BUILD_FINISHED"}, + Category: category, }, &cli.StringFlag{ - Name: "build.deploy-to", - Usage: "build deploy to", - EnvVars: []string{"DRONE_DEPLOY_TO"}, + Name: "build.deploy-to", + Usage: "build deploy to", + EnvVars: []string{"DRONE_DEPLOY_TO"}, + Category: category, }, &cli.IntFlag{ - Name: "build.deploy-id", - Usage: "build deploy id", - EnvVars: []string{"DRONE_DEPLOY_ID"}, + Name: "build.deploy-id", + Usage: "build deploy id", + EnvVars: []string{"DRONE_DEPLOY_ID"}, + Category: category, }, &cli.StringSliceFlag{ - Name: "build.failed-stages", - Usage: "build failed stages", - EnvVars: []string{"DRONE_FAILED_STAGES"}, + Name: "build.failed-stages", + Usage: "build failed stages", + EnvVars: []string{"DRONE_FAILED_STAGES"}, + Category: category, }, &cli.StringSliceFlag{ - Name: "build.failed-steps", - Usage: "build failed steps", - EnvVars: []string{"DRONE_FAILED_STEPS"}, + Name: "build.failed-steps", + Usage: "build failed steps", + EnvVars: []string{"DRONE_FAILED_STEPS"}, + Category: category, }, } } diff --git a/urfave/calver.go b/urfave/calver.go index 878953e..c10b2cd 100644 --- a/urfave/calver.go +++ b/urfave/calver.go @@ -8,7 +8,7 @@ import ( ) // calVerFlags has the cli.Flags for the drone.CalVer. -func calVerFlags() []cli.Flag { +func calVerFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "calver.version", @@ -16,6 +16,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER", }, + Category: category, }, &cli.StringFlag{ Name: "calver.major", @@ -23,6 +24,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER_MAJOR", }, + Category: category, }, &cli.StringFlag{ Name: "calver.minor", @@ -30,6 +32,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER_MINOR", }, + Category: category, }, &cli.StringFlag{ Name: "calver.micro", @@ -37,6 +40,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER_MICRO", }, + Category: category, }, &cli.StringFlag{ Name: "calver.modifier", @@ -44,6 +48,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER_MODIFIER", }, + Category: category, }, &cli.StringFlag{ Name: "calver.short", @@ -51,6 +56,7 @@ func calVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_CALVER_SHORT", }, + Category: category, }, } } diff --git a/urfave/commit.go b/urfave/commit.go index 573da7b..3b8b122 100644 --- a/urfave/commit.go +++ b/urfave/commit.go @@ -12,7 +12,7 @@ import ( ) // commitFlags has the cli.Flags for the drone.Commit. -func commitFlags() []cli.Flag { +func commitFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "commit.sha", @@ -21,6 +21,7 @@ func commitFlags() []cli.Flag { "DRONE_COMMIT", "DRONE_COMMIT_SHA", }, + Category: category, }, &cli.StringFlag{ Name: "commit.before", @@ -28,6 +29,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_BEFORE", }, + Category: category, }, &cli.StringFlag{ Name: "commit.after", @@ -35,6 +37,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_AFTER", }, + Category: category, }, &cli.StringFlag{ Name: "commit.ref", @@ -42,6 +45,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_REF", }, + Category: category, }, &cli.StringFlag{ Name: "commit.branch", @@ -49,12 +53,14 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_BRANCH", }, + Category: category, }, &cli.StringFlag{ Name: "commit.link", Usage: "commit link", EnvVars: []string{ "DRONE_COMMIT_LINK", }, + Category: category, }, &cli.StringFlag{ Name: "commit.message", @@ -62,6 +68,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_MESSAGE", }, + Category: category, }, &cli.StringFlag{ Name: "commit.author", @@ -69,6 +76,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_AUTHOR", }, + Category: category, }, &cli.StringFlag{ Name: "commit.author-name", @@ -76,6 +84,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_AUTHOR_NAME", }, + Category: category, }, &cli.StringFlag{ Name: "commit.author-email", @@ -83,6 +92,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_AUTHOR_EMAIL", }, + Category: category, }, &cli.StringFlag{ Name: "commit.author-avatar", @@ -90,6 +100,7 @@ func commitFlags() []cli.Flag { EnvVars: []string{ "DRONE_COMMIT_AUTHOR_AVATAR", }, + Category: category, }, } } diff --git a/urfave/logging.go b/urfave/logging.go index 4f55a01..874a834 100644 --- a/urfave/logging.go +++ b/urfave/logging.go @@ -12,12 +12,13 @@ import ( ) // loggingFlags has the cli.Flags for logging config. -func loggingFlags() []cli.Flag { +func loggingFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ - Name: "log-level", - Usage: "log level", - EnvVars: []string{"PLUGIN_LOG_LEVEL"}, + Name: "log-level", + Usage: "log level", + EnvVars: []string{"PLUGIN_LOG_LEVEL"}, + Category: category, }, } } diff --git a/urfave/network.go b/urfave/network.go index 3736b7c..b0c9cd3 100644 --- a/urfave/network.go +++ b/urfave/network.go @@ -20,12 +20,13 @@ import ( ) // networkFlags has the cli.Flags for the drone.Network. -func networkFlags() []cli.Flag { +func networkFlags(category string) []cli.Flag { return []cli.Flag{ &cli.BoolFlag{ - Name: "transport.skip-verify", - Usage: "skip ssl verify", - EnvVars: []string{"PLUGIN_SKIP_VERIFY"}, + Name: "transport.skip-verify", + Usage: "skip ssl verify", + EnvVars: []string{"PLUGIN_SKIP_VERIFY"}, + Category: category, }, } } diff --git a/urfave/repo.go b/urfave/repo.go index 836fcfd..d8919a4 100644 --- a/urfave/repo.go +++ b/urfave/repo.go @@ -12,7 +12,7 @@ import ( ) // repoFlags has the cli.Flags for the drone.Repo -func repoFlags() []cli.Flag { +func repoFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "repo.slug", @@ -20,6 +20,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO", }, + Category: category, }, &cli.StringFlag{ Name: "repo.scm", @@ -27,6 +28,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_SCM", }, + Category: category, }, &cli.StringFlag{ Name: "repo.owner", @@ -35,6 +37,7 @@ func repoFlags() []cli.Flag { "DRONE_REPO_OWNER", "DRONE_REPO_NAMESPACE", }, + Category: category, }, &cli.StringFlag{ Name: "repo.name", @@ -42,6 +45,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_NAME", }, + Category: category, }, &cli.StringFlag{ Name: "repo.link", @@ -49,6 +53,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_LINK", }, + Category: category, }, &cli.StringFlag{ Name: "repo.branch", @@ -56,6 +61,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_BRANCH", }, + Category: category, }, &cli.StringFlag{ Name: "repo.http-url", @@ -64,6 +70,7 @@ func repoFlags() []cli.Flag { "DRONE_REMOTE_URL", "DRONE_GIT_HTTP_URL", }, + Category: category, }, &cli.StringFlag{ Name: "repo.ssh-url", @@ -71,6 +78,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_GIT_SSH_URL", }, + Category: category, }, &cli.StringFlag{ Name: "repo.visibility", @@ -78,6 +86,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_VISIBILITY", }, + Category: category, }, &cli.BoolFlag{ Name: "repo.private", @@ -85,6 +94,7 @@ func repoFlags() []cli.Flag { EnvVars: []string{ "DRONE_REPO_PRIVATE", }, + Category: category, }, } } diff --git a/urfave/semver.go b/urfave/semver.go index c5d7b55..291edcf 100644 --- a/urfave/semver.go +++ b/urfave/semver.go @@ -12,7 +12,7 @@ import ( ) // semVerFlags has the cli.Flags for the drone.SemVer. -func semVerFlags() []cli.Flag { +func semVerFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "semver.version", @@ -20,6 +20,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER", }, + Category: category, }, &cli.StringFlag{ Name: "semver.major", @@ -27,6 +28,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_MAJOR", }, + Category: category, }, &cli.StringFlag{ Name: "semver.minor", @@ -34,6 +36,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_MINOR", }, + Category: category, }, &cli.StringFlag{ Name: "semver.patch", @@ -41,6 +44,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_PATCH", }, + Category: category, }, &cli.StringFlag{ Name: "semver.prerelease", @@ -48,6 +52,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_PRERELEASE", }, + Category: category, }, &cli.StringFlag{ Name: "semver.build", @@ -55,6 +60,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_BUILD", }, + Category: category, }, &cli.StringFlag{ Name: "semver.short", @@ -62,6 +68,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_SHORT", }, + Category: category, }, &cli.StringFlag{ Name: "semver.error", @@ -69,6 +76,7 @@ func semVerFlags() []cli.Flag { EnvVars: []string{ "DRONE_SEMVER_ERROR", }, + Category: category, }, } } diff --git a/urfave/stage.go b/urfave/stage.go index cc58634..d2f32b0 100644 --- a/urfave/stage.go +++ b/urfave/stage.go @@ -14,7 +14,7 @@ import ( ) // stageFlags has the cli.Flags for the drone.Stage. -func stageFlags() []cli.Flag { +func stageFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "stage.kind", @@ -22,6 +22,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_KIND", }, + Category: category, }, &cli.StringFlag{ Name: "stage.type", @@ -29,6 +30,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_TYPE", }, + Category: category, }, &cli.StringFlag{ Name: "stage.name", @@ -36,6 +38,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_NAME", }, + Category: category, }, &cli.IntFlag{ Name: "stage.number", @@ -43,6 +46,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_NUMBER", }, + Category: category, }, &cli.StringFlag{ Name: "stage.machine", @@ -50,6 +54,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_MACHINE", }, + Category: category, }, &cli.StringFlag{ Name: "stage.os", @@ -57,6 +62,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_OS", }, + Category: category, }, &cli.StringFlag{ Name: "stage.arch", @@ -64,6 +70,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_ARCH", }, + Category: category, }, &cli.StringFlag{ Name: "stage.variant", @@ -71,6 +78,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_VARIANT", }, + Category: category, }, &cli.StringFlag{ Name: "stage.version", @@ -78,6 +86,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_VERSION", }, + Category: category, }, &cli.StringFlag{ Name: "stage.status", @@ -85,6 +94,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_STATUS", }, + Category: category, }, &cli.Int64Flag{ Name: "stage.started", @@ -92,6 +102,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_STARTED", }, + Category: category, }, &cli.Int64Flag{ Name: "stage.finished", @@ -99,6 +110,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_FINISHED", }, + Category: category, }, &cli.StringSliceFlag{ Name: "stage.depends-on", @@ -106,6 +118,7 @@ func stageFlags() []cli.Flag { EnvVars: []string{ "DRONE_STAGE_DEPENDS_ON", }, + Category: category, }, } } diff --git a/urfave/step.go b/urfave/step.go index acb2844..78a79fd 100644 --- a/urfave/step.go +++ b/urfave/step.go @@ -12,7 +12,7 @@ import ( ) // stepFlags has the cli.Flags for the drone.Step. -func stepFlags() []cli.Flag { +func stepFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "step.name", @@ -20,6 +20,7 @@ func stepFlags() []cli.Flag { EnvVars: []string{ "DRONE_STEP_NAME", }, + Category: category, }, &cli.IntFlag{ Name: "step.number", @@ -27,6 +28,7 @@ func stepFlags() []cli.Flag { EnvVars: []string{ "DRONE_STEP_NUMBER", }, + Category: category, }, } } diff --git a/urfave/system.go b/urfave/system.go index 9c9e77c..41bc9b2 100644 --- a/urfave/system.go +++ b/urfave/system.go @@ -12,7 +12,7 @@ import ( ) // systemFlags has the cli.Flags for the drone.System. -func systemFlags() []cli.Flag { +func systemFlags(category string) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "system.proto", @@ -20,6 +20,7 @@ func systemFlags() []cli.Flag { EnvVars: []string{ "DRONE_SYSTEM_PROTO", }, + Category: category, }, &cli.StringFlag{ Name: "system.host", @@ -28,6 +29,7 @@ func systemFlags() []cli.Flag { "DRONE_SYSTEM_HOST", "DRONE_SYSTEM_HOSTNAME", }, + Category: category, }, &cli.StringFlag{ Name: "system.version", @@ -35,6 +37,7 @@ func systemFlags() []cli.Flag { EnvVars: []string{ "DRONE_SYSTEM_VERSION", }, + Category: category, }, } } diff --git a/urfave/urfave.go b/urfave/urfave.go index d732be3..a095d77 100644 --- a/urfave/urfave.go +++ b/urfave/urfave.go @@ -11,20 +11,31 @@ import ( "github.com/urfave/cli/v2" ) +var ( + FlagsBuildCategory = "Drone Build Flags" + FlagsRepoCategory = "Drone Repo Flags" + FlagsCommitCategory = "Drone Commit Flags" + FlagsStageCategory = "Drone Stage Flags" + FlagsStepCategory = "Drone Step Flags" + FlagsVersioningCategory = "Drone Versioning Flags" + FlagsSystemCategory = "Drone System Flags" + FlagsPluginCategory = "Plugin Flags" +) + // Flags has the cli.Flags for the Drone plugin. func Flags() []cli.Flag { flags := []cli.Flag{} - flags = append(flags, buildFlags()...) - flags = append(flags, repoFlags()...) - flags = append(flags, commitFlags()...) - flags = append(flags, stageFlags()...) - flags = append(flags, stepFlags()...) - flags = append(flags, semVerFlags()...) - flags = append(flags, calVerFlags()...) - flags = append(flags, systemFlags()...) - flags = append(flags, networkFlags()...) - flags = append(flags, loggingFlags()...) + flags = append(flags, buildFlags(FlagsBuildCategory)...) + flags = append(flags, repoFlags(FlagsRepoCategory)...) + flags = append(flags, commitFlags(FlagsCommitCategory)...) + flags = append(flags, stageFlags(FlagsStageCategory)...) + flags = append(flags, stepFlags(FlagsStepCategory)...) + flags = append(flags, semVerFlags(FlagsVersioningCategory)...) + flags = append(flags, calVerFlags(FlagsVersioningCategory)...) + flags = append(flags, systemFlags(FlagsSystemCategory)...) + flags = append(flags, networkFlags(FlagsPluginCategory)...) + flags = append(flags, loggingFlags(FlagsPluginCategory)...) return flags }