drone-plugin-lib/urfave/stage.go

144 lines
3.1 KiB
Go
Raw Normal View History

2022-05-03 20:03:37 +00:00
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"time"
2022-05-29 11:41:22 +00:00
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// stageFlags has the cli.Flags for the drone.Stage.
2022-05-29 11:15:31 +00:00
func stageFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "stage.kind",
Usage: "stage kind",
EnvVars: []string{
"DRONE_STAGE_KIND",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.type",
Usage: "stage type",
EnvVars: []string{
"DRONE_STAGE_TYPE",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.name",
Usage: "stage name",
EnvVars: []string{
"DRONE_STAGE_NAME",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.IntFlag{
Name: "stage.number",
Usage: "stage number",
EnvVars: []string{
"DRONE_STAGE_NUMBER",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.machine",
Usage: "stage machine",
EnvVars: []string{
"DRONE_STAGE_MACHINE",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.os",
Usage: "stage os",
EnvVars: []string{
"DRONE_STAGE_OS",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.arch",
Usage: "stage arch",
EnvVars: []string{
"DRONE_STAGE_ARCH",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.variant",
Usage: "stage variant",
EnvVars: []string{
"DRONE_STAGE_VARIANT",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.version",
Usage: "stage version",
EnvVars: []string{
"DRONE_STAGE_VERSION",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringFlag{
Name: "stage.status",
Usage: "stage status",
EnvVars: []string{
"DRONE_STAGE_STATUS",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.Int64Flag{
Name: "stage.started",
Usage: "stage started",
EnvVars: []string{
"DRONE_STAGE_STARTED",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.Int64Flag{
Name: "stage.finished",
Usage: "stage finished",
EnvVars: []string{
"DRONE_STAGE_FINISHED",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
&cli.StringSliceFlag{
Name: "stage.depends-on",
Usage: "stage depends on",
EnvVars: []string{
"DRONE_STAGE_DEPENDS_ON",
},
2022-05-29 11:15:31 +00:00
Category: category,
},
}
}
// stageFromContext creates a drone.Stage from the cli.Context.
func stageFromContext(ctx *cli.Context) drone.Stage {
return drone.Stage{
Kind: ctx.String("stage.kind"),
Type: ctx.String("stage.type"),
Name: ctx.String("stage.name"),
Number: ctx.Int("stage.number"),
Machine: ctx.String("stage.machine"),
OS: ctx.String("stage.os"),
Arch: ctx.String("stage.arch"),
Variant: ctx.String("stage.variant"),
Version: ctx.String("stage.version"),
Status: ctx.String("stage.status"),
Started: time.Unix(ctx.Int64("stage.started"), 0),
Finished: time.Unix(ctx.Int64("stage.finished"), 0),
DependsOn: ctx.StringSlice("stage.depends-on"),
}
}