0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-11-14 09:40:38 +00:00
wp-plugin-go/pkg/urfave/urfave.go

582 lines
16 KiB
Go
Raw Normal View History

2019-09-06 23:34:27 +00:00
// Copyright (c) 2019, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
// Package urfave provides helpers for interacting with the `urfave/cli`
// package when creating plugins for use by the Drone CI/CD service.
//
// Drone communicates to plugins by passing in environment variables that have
// information on the currently executing build. The `urfave/cli` package can
// read these environment variables and extract them into structs.
//
// import(
// "github.com/drone-plugins/drone-plugin-lib/pkg/urfave"
// "github.com/urfave/cli"
// )
//
// func main() {
// app := cli.New()
// app.Name = "my awesome Drone plugin"
// app.Run = run
// app.Flags = []cli.Flags{
// // All my plugin flags
// }
// app.Flags = append(
// app.Flags,
2019-10-10 20:36:20 +00:00
// urfave.commitFlags()...,
2019-09-06 23:34:27 +00:00
// )
// }
package urfave
import (
2019-09-07 00:13:21 +00:00
"time"
2019-09-06 23:34:27 +00:00
"github.com/urfave/cli"
"github.com/drone-plugins/drone-plugin-lib/internal/environ"
"github.com/drone-plugins/drone-plugin-lib/pkg/plugin"
2019-09-06 23:34:27 +00:00
)
2019-09-10 00:03:55 +00:00
//---------------------------------------------------------------------
2019-10-10 20:05:11 +00:00
// Pipeline
//---------------------------------------------------------------------
// PipelineFlags has the cli.Flags for the plugin.Pipeline.
func PipelineFlags() []cli.Flag {
flags := []cli.Flag{}
2019-10-10 20:36:20 +00:00
flags = append(flags, buildFlags()...)
flags = append(flags, repoFlags()...)
flags = append(flags, commitFlags()...)
flags = append(flags, stageFlags()...)
flags = append(flags, stepFlags()...)
flags = append(flags, semVerFlags()...)
2019-10-10 20:05:11 +00:00
return flags
}
// PipelineFromContext creates a plugin.Pipeline from the cli.Context.
2019-10-10 20:36:20 +00:00
func PipelineFromContext(ctx *cli.Context) plugin.Pipeline {
2019-10-10 20:05:11 +00:00
return plugin.Pipeline{
2019-10-10 20:36:20 +00:00
Build: buildFromContext(ctx),
Repo: repoFromContext(ctx),
Commit: commitFromContext(ctx),
Stage: stageFromContext(ctx),
Step: stepFromContext(ctx),
SemVer: semVerFromContext(ctx),
2019-10-10 20:05:11 +00:00
}
}
//---------------------------------------------------------------------
2019-09-10 00:03:55 +00:00
// Build Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
buildActionFlag = "build.action"
buildCreatedFlag = "build.created"
buildDeployToFlag = "build.deploy-to"
buildEventFlag = "build.event"
buildFailedStagesFlag = "build.failed-stages"
buildFailedStepsFlag = "build.failed-steps"
buildFinishedFlag = "build.finished"
buildNumberFlag = "build.number"
buildParentFlag = "build.parent"
buildPullRequestFlag = "build.pull-request"
buildSourceBranchFlag = "build.source-branch"
buildStartedFlag = "build.started"
buildStatusFlag = "build.status"
buildTagFlag = "build.tag"
buildTargetBranchFlag = "build.target-branch"
2019-09-10 00:03:55 +00:00
)
2019-10-10 20:36:20 +00:00
// buildFlags has the cli.Flags for the plugin.Build.
func buildFlags() []cli.Flag {
2019-09-10 00:03:55 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildActionFlag,
2019-09-10 00:03:55 +00:00
Usage: "build action",
EnvVar: environ.BuildActionEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildCreatedFlag,
2019-09-10 00:03:55 +00:00
Usage: "build created",
EnvVar: environ.BuildCreatedEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildDeployToFlag,
2019-09-10 00:03:55 +00:00
Usage: "build deploy to",
EnvVar: environ.BuildDeployToEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildEventFlag,
2019-09-10 00:03:55 +00:00
Usage: "build event",
EnvVar: environ.BuildEventEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringSliceFlag{
2019-10-10 20:36:20 +00:00
Name: buildFailedStagesFlag,
2019-09-10 00:03:55 +00:00
Usage: "build failed stages",
EnvVar: environ.BuildFailedStagesEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringSliceFlag{
2019-10-10 20:36:20 +00:00
Name: buildFailedStepsFlag,
2019-09-10 00:03:55 +00:00
Usage: "build failed steps",
EnvVar: environ.BuildFailedStepsEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildFinishedFlag,
2019-09-10 00:03:55 +00:00
Usage: "build finished",
EnvVar: environ.BuildFinishedEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.IntFlag{
2019-10-10 20:36:20 +00:00
Name: buildNumberFlag,
2019-09-10 00:03:55 +00:00
Usage: "build number",
EnvVar: environ.BuildNumberEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.IntFlag{
2019-10-10 20:36:20 +00:00
Name: buildParentFlag,
2019-09-10 00:03:55 +00:00
Usage: "build parent",
EnvVar: environ.BuildParentEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.IntFlag{
2019-10-10 20:36:20 +00:00
Name: buildPullRequestFlag,
2019-09-10 00:03:55 +00:00
Usage: "build pull request",
EnvVar: environ.BuildPullRequestEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildSourceBranchFlag,
2019-09-10 00:03:55 +00:00
Usage: "build source branch",
EnvVar: environ.BuildSourceBranchEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildStartedFlag,
2019-09-10 00:03:55 +00:00
Usage: "build started",
EnvVar: environ.BuildStartedEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildStatusFlag,
2019-09-10 00:03:55 +00:00
Usage: "build status",
EnvVar: environ.BuildStatusEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildTagFlag,
2019-09-10 00:03:55 +00:00
Usage: "build tag",
EnvVar: environ.BuildTagEnvVar,
2019-09-10 00:03:55 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: buildTargetBranchFlag,
2019-09-10 00:03:55 +00:00
Usage: "build target branch",
EnvVar: environ.BuildTargetBranchEnvVar,
2019-09-10 00:03:55 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// buildFromContext creates a plugin.Build from the cli.Context.
func buildFromContext(ctx *cli.Context) plugin.Build {
2019-09-10 00:03:55 +00:00
return plugin.Build{
2019-10-10 20:36:20 +00:00
Action: ctx.String(buildActionFlag),
Created: time.Unix(ctx.Int64(buildCreatedFlag), 0),
DeployTo: ctx.String(buildDeployToFlag),
Event: ctx.String(buildEventFlag),
FailedStages: ctx.StringSlice(buildFailedStagesFlag),
FailedSteps: ctx.StringSlice(buildFailedStepsFlag),
Finished: time.Unix(ctx.Int64(buildFinishedFlag), 0),
Number: ctx.Int(buildNumberFlag),
Parent: ctx.Int(buildParentFlag),
PullRequest: ctx.Int(buildPullRequestFlag),
SourceBranch: ctx.String(buildSourceBranchFlag),
Started: time.Unix(ctx.Int64(buildStartedFlag), 0),
Status: ctx.String(buildStatusFlag),
Tag: ctx.String(buildTagFlag),
TargetBranch: ctx.String(buildTargetBranchFlag),
2019-09-10 00:03:55 +00:00
}
}
2019-09-09 21:02:13 +00:00
//---------------------------------------------------------------------
// Repo Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
repoDefaultBranchFlag = "repo.branch"
repoFullNameFlag = "repo.full-name"
repoLinkFlag = "repo.link"
repoNameFlag = "repo.name"
repoOwnerFlag = "repo.owner"
repoPrivateFlag = "repo.private"
repoRemoteURLFlag = "repo.remote-url"
repoSCMFlag = "repo.scm"
repoVisibilityFlag = "repo.visibility"
2019-09-09 21:02:13 +00:00
)
2019-10-10 20:36:20 +00:00
// repoFlags has the cli.Flags for the plugin.Repo
func repoFlags() []cli.Flag {
2019-09-09 21:02:13 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoDefaultBranchFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo default branch",
EnvVar: environ.RepoDefaultBranchEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoFullNameFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo full name",
EnvVar: environ.RepoFullNameEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoLinkFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo link",
EnvVar: environ.RepoLinkEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoNameFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo name",
EnvVar: environ.RepoNameEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoOwnerFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo owner",
EnvVar: environ.RepoOwnerEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.BoolFlag{
2019-10-10 20:36:20 +00:00
Name: repoPrivateFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo private",
EnvVar: environ.RepoPrivateEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoRemoteURLFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo remote url",
EnvVar: environ.RepoRemoteURLEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoSCMFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo scm",
EnvVar: environ.RepoSCMEnvVar,
2019-09-09 21:02:13 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: repoVisibilityFlag,
2019-09-09 21:02:13 +00:00
Usage: "repo visibility",
EnvVar: environ.RepoVisibilityEnvVar,
2019-09-09 21:02:13 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// repoFromContext creates a plugin.Repo from the cli.Context.
func repoFromContext(ctx *cli.Context) plugin.Repo {
2019-09-09 21:02:13 +00:00
return plugin.Repo{
2019-10-10 20:36:20 +00:00
DefaultBranch: ctx.String(repoDefaultBranchFlag),
FullName: ctx.String(repoFullNameFlag),
Link: ctx.String(repoLinkFlag),
Name: ctx.String(repoNameFlag),
Owner: ctx.String(repoOwnerFlag),
Private: ctx.Bool(repoPrivateFlag),
RemoteURL: ctx.String(repoRemoteURLFlag),
SCM: ctx.String(repoSCMFlag),
Visibility: ctx.String(repoVisibilityFlag),
2019-09-09 21:02:13 +00:00
}
}
2019-09-09 23:27:59 +00:00
//---------------------------------------------------------------------
// Commit Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
commitAfterFlag = "commit.after"
commitAuthorFlag = "commit.author"
commitAuthorAvatarFlag = "commit.author-avatar"
commitAuthorEmailFlag = "commit.author-email"
commitAuthorNameFlag = "commit.author-name"
commitBeforeFlag = "commit.before"
commitBranchFlag = "commit.branch"
commitLinkFlag = "commit.link"
commitMessageFlag = "commit.message"
commitRefFlag = "commit.ref"
commitSHAFlag = "commit.sha"
2019-09-09 23:27:59 +00:00
)
2019-10-10 20:36:20 +00:00
// commitFlags has the cli.Flags for the plugin.Commit.
func commitFlags() []cli.Flag {
2019-09-09 23:27:59 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitAfterFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit after",
EnvVar: environ.CommitAfterEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitAuthorFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit author",
EnvVar: environ.CommitAuthorEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitAuthorAvatarFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit author avatar",
EnvVar: environ.CommitAuthorAvatarEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitAuthorEmailFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit author email",
EnvVar: environ.CommitAuthorEmailEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitAuthorNameFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit author name",
EnvVar: environ.CommitAuthorNameEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitBeforeFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit before",
EnvVar: environ.CommitBeforeEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitBranchFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit branch",
EnvVar: environ.CommitBranchEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitLinkFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit link",
EnvVar: environ.CommitLinkEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitMessageFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit message",
EnvVar: environ.CommitMessageEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitRefFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit ref",
EnvVar: environ.CommitRefEnvVar,
2019-09-09 23:27:59 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: commitSHAFlag,
2019-09-09 23:27:59 +00:00
Usage: "commit sha",
EnvVar: environ.CommitSHAEnvVar,
2019-09-09 23:27:59 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// commitFromContext creates a plugin.Commit from the cli.Context.
func commitFromContext(ctx *cli.Context) plugin.Commit {
2019-09-09 23:27:59 +00:00
return plugin.Commit{
2019-10-10 20:36:20 +00:00
After: ctx.String(commitAfterFlag),
Author: ctx.String(commitAuthorFlag),
AuthorAvatar: ctx.String(commitAuthorAvatarFlag),
AuthorEmail: ctx.String(commitAuthorEmailFlag),
AuthorName: ctx.String(commitAuthorNameFlag),
Before: ctx.String(commitBeforeFlag),
Branch: ctx.String(commitBranchFlag),
Link: ctx.String(commitLinkFlag),
Message: ctx.String(commitMessageFlag),
Ref: ctx.String(commitRefFlag),
SHA: ctx.String(commitSHAFlag),
2019-09-09 23:27:59 +00:00
}
}
2019-09-07 00:13:21 +00:00
//---------------------------------------------------------------------
// Stage Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
stageArchFlag = "stage.arch"
stageDependsOnFlag = "stage.depends-on"
stageFinishedFlag = "stage.finished"
stageKindFlag = "stage.kind"
stageMachineFlag = "stage.machine"
stageNameFlag = "stage.name"
stageNumberFlag = "stage.number"
stageOSFlag = "stage.os"
stageStartedFlag = "stage.started"
stageStatusFlag = "stage.status"
stageTypeFlag = "stage.type"
stageVariantFlag = "stage.variant"
stageVersionFlag = "stage.version"
2019-09-07 00:13:21 +00:00
)
2019-10-10 20:36:20 +00:00
// stageFlags has the cli.Flags for the plugin.Stage
func stageFlags() []cli.Flag {
2019-09-07 00:13:21 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageArchFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage arch",
EnvVar: environ.StageArchEnvVar,
2019-09-07 00:13:21 +00:00
},
cli.StringSliceFlag{
2019-10-10 20:36:20 +00:00
Name: stageDependsOnFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage depends on",
EnvVar: environ.StageDependsOnEnvVar,
2019-09-07 00:13:21 +00:00
},
cli.Int64Flag{
2019-10-10 20:36:20 +00:00
Name: stageFinishedFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage finished",
EnvVar: environ.StageFinishedEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageKindFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage kind",
EnvVar: environ.StageKindEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageMachineFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage machine",
EnvVar: environ.StageMachineEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageNameFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage name",
EnvVar: environ.StageNameEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.IntFlag{
2019-10-10 20:36:20 +00:00
Name: stageNumberFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage number",
EnvVar: environ.StageNumberEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageOSFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage os",
EnvVar: environ.StageOSEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.Int64Flag{
2019-10-10 20:36:20 +00:00
Name: stageStartedFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage started",
EnvVar: environ.StageStartedEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageStatusFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage status",
EnvVar: environ.StageStatusEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageTypeFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage type",
EnvVar: environ.StageTypeEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageVariantFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage variant",
EnvVar: environ.StageVariantEnvVar,
2019-09-07 00:13:21 +00:00
}, cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stageVersionFlag,
2019-09-07 00:13:21 +00:00
Usage: "stage version",
EnvVar: environ.StageVersionEnvVar,
2019-09-07 00:13:21 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// stageFromContext creates a plugin.Stage from the cli.Context.
func stageFromContext(ctx *cli.Context) plugin.Stage {
2019-09-07 00:13:21 +00:00
return plugin.Stage{
2019-10-10 20:36:20 +00:00
Arch: ctx.String(stageArchFlag),
DependsOn: ctx.StringSlice(stageDependsOnFlag),
Finished: time.Unix(ctx.Int64(stageFinishedFlag), 0),
Kind: ctx.String(stageKindFlag),
Machine: ctx.String(stageMachineFlag),
Name: ctx.String(stageNameFlag),
Number: ctx.Int(stageNumberFlag),
OS: ctx.String(stageOSFlag),
Started: time.Unix(ctx.Int64(stageStartedFlag), 0),
Status: ctx.String(stageStatusFlag),
Type: ctx.String(stageTypeFlag),
Variant: ctx.String(stageVariantFlag),
Version: ctx.String(stageVersionFlag),
2019-09-07 00:13:21 +00:00
}
}
2019-09-06 23:34:27 +00:00
//---------------------------------------------------------------------
// Step Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
// stepNameFlag corresponds to plugin.Step.Name.
stepNameFlag = "step.name"
// stepNumberFlag corresponds to plugin.Step.Number.
stepNumberFlag = "step.number"
2019-09-06 23:34:27 +00:00
)
2019-10-10 20:36:20 +00:00
// stepFlags has the cli.Flags for the plugin.Step.
func stepFlags() []cli.Flag {
2019-09-06 23:34:27 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stepNameFlag,
2019-09-06 23:34:27 +00:00
Usage: "step name",
EnvVar: environ.StepNameEnvVar,
2019-09-06 23:34:27 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: stepNumberFlag,
2019-09-06 23:34:27 +00:00
Usage: "step number",
EnvVar: environ.StepNumberEnvVar,
2019-09-06 23:34:27 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// stepFromContext creates a plugin.Step from the cli.Context.
func stepFromContext(ctx *cli.Context) plugin.Step {
2019-09-06 23:34:27 +00:00
return plugin.Step{
2019-10-10 20:36:20 +00:00
Name: ctx.String(stepNameFlag),
Number: ctx.Int(stepNumberFlag),
2019-09-06 23:34:27 +00:00
}
}
2019-09-09 21:27:12 +00:00
//---------------------------------------------------------------------
// SemVer Flags
//---------------------------------------------------------------------
const (
2019-10-10 20:36:20 +00:00
semVerBuildFlag = "semver.build"
semVerErrorFlag = "semver.error"
semVerMajorFlag = "semver.major"
semVerMinorFlag = "semver.minor"
semVerPatchFlag = "semver.patch"
semVerPrereleaseFlag = "semver.prerelease"
semVerShortFlag = "semver.short"
semVerVersionFlag = "semver.version"
2019-09-09 21:27:12 +00:00
)
2019-10-10 20:36:20 +00:00
// semVerFlags has the cli.Flags for the plugin.SemVer.
func semVerFlags() []cli.Flag {
2019-09-09 21:27:12 +00:00
return []cli.Flag{
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerBuildFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver build",
EnvVar: environ.SemVerBuildEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerErrorFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver error",
EnvVar: environ.SemVerErrorEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerMajorFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver major",
EnvVar: environ.SemVerMajorEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerMinorFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver minor",
EnvVar: environ.SemVerMinorEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerPatchFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver patch",
EnvVar: environ.SemVerPatchEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerPrereleaseFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver prerelease",
EnvVar: environ.SemVerPrereleaseEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerShortFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver short",
EnvVar: environ.SemVerShortEnvVar,
2019-09-09 21:27:12 +00:00
},
cli.StringFlag{
2019-10-10 20:36:20 +00:00
Name: semVerVersionFlag,
2019-09-09 21:27:12 +00:00
Usage: "semver version",
EnvVar: environ.SemVerVersionEnvVar,
2019-09-09 21:27:12 +00:00
},
}
}
2019-10-10 20:36:20 +00:00
// semVerFromContext creates a plugin.Step from the cli.Context.
func semVerFromContext(ctx *cli.Context) plugin.SemVer {
2019-09-09 21:27:12 +00:00
return plugin.SemVer{
2019-10-10 20:36:20 +00:00
Build: ctx.String(semVerBuildFlag),
Error: ctx.String(semVerErrorFlag),
Major: ctx.String(semVerMajorFlag),
Minor: ctx.String(semVerMinorFlag),
Patch: ctx.String(semVerPatchFlag),
Prerelease: ctx.String(semVerPrereleaseFlag),
Short: ctx.String(semVerShortFlag),
Version: ctx.String(semVerVersionFlag),
2019-09-09 21:27:12 +00:00
}
}