feat: group flags by categories (#6)

This commit is contained in:
Robert Kaussow 2022-05-29 13:15:31 +02:00 committed by GitHub
parent 69400ab6b2
commit dcb03e1fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 164 additions and 80 deletions

View File

@ -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"},
Category: category,
},
&cli.IntFlag{
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"},
Category: category,
},
&cli.StringFlag{
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"},
Category: category,
},
&cli.IntFlag{
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"},
Category: category,
},
&cli.StringFlag{
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"},
Category: category,
},
&cli.StringFlag{
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"},
Category: category,
},
&cli.StringFlag{
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"},
Category: category,
},
&cli.StringFlag{
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"},
Category: category,
},
&cli.IntFlag{
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"},
Category: category,
},
&cli.StringSliceFlag{
Name: "build.failed-steps",
Usage: "build failed steps",
EnvVars: []string{"DRONE_FAILED_STEPS"},
Category: category,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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"},
Category: category,
},
}
}

View File

@ -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"},
Category: category,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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,
},
}
}

View File

@ -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
}