mirror of
https://github.com/thegeeklab/wp-plugin-go.git
synced 2024-11-22 00:20:38 +00:00
Add urfave parsing of Step
This commit is contained in:
parent
537f56a596
commit
149d8bc34f
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module github.com/drone-plugins/drone-plugin-lib
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/urfave/cli v1.21.0
|
5
go.sum
Normal file
5
go.sum
Normal file
@ -0,0 +1,5 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE=
|
||||
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
72
pkg/urfave/urfave.go
Normal file
72
pkg/urfave/urfave.go
Normal file
@ -0,0 +1,72 @@
|
||||
// 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,
|
||||
// urfave.CommitFlags()...,
|
||||
// )
|
||||
// }
|
||||
package urfave
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-plugin-lib/pkg/plugin"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Step Flags
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
// StepNameFlag is the flag name for setting plugin.Step.Name.
|
||||
StepNameFlag = "step.name"
|
||||
// StepNumberFlag is the flag name for setting plugin.Step.Number.
|
||||
StepNumberFlag = "step.number"
|
||||
)
|
||||
|
||||
// StepFlags has the cli.Flags for the plugin.Step.
|
||||
func StepFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: StepNameFlag,
|
||||
Usage: "step name",
|
||||
EnvVar: plugin.StepNameEnvVar,
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: StepNumberFlag,
|
||||
Usage: "step number",
|
||||
EnvVar: plugin.StepNumberEnvVar,
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// StepFromContext creates a plugin.Step from the cli.Context.
|
||||
func StepFromContext(ctx cli.Context) plugin.Step {
|
||||
return plugin.Step{
|
||||
Name: ctx.String(StepNameFlag),
|
||||
Number: ctx.Int(StepNumberFlag),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user