2020-02-21 13:56:09 +02:00
|
|
|
// Code generated by piper's step-generator. DO NOT EDIT.
|
|
|
|
|
2019-10-31 14:57:29 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-01-31 15:06:08 +02:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2019-10-31 14:57:29 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/config"
|
2019-11-04 15:43:33 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2020-01-29 14:17:54 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
2019-10-31 14:57:29 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type versionOptions struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// VersionCommand Returns the version of the piper binary
|
|
|
|
func VersionCommand() *cobra.Command {
|
|
|
|
metadata := versionMetadata()
|
2020-02-04 11:46:43 +02:00
|
|
|
var stepConfig versionOptions
|
2020-01-31 15:06:08 +02:00
|
|
|
var startTime time.Time
|
2020-01-15 13:16:25 +02:00
|
|
|
|
2019-10-31 14:57:29 +02:00
|
|
|
var createVersionCmd = &cobra.Command{
|
|
|
|
Use: "version",
|
|
|
|
Short: "Returns the version of the piper binary",
|
|
|
|
Long: `Writes the commit hash and the tag (if any) to stdout and exits with 0.`,
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2020-01-31 15:06:08 +02:00
|
|
|
startTime = time.Now()
|
2019-11-04 15:43:33 +02:00
|
|
|
log.SetStepName("version")
|
2019-11-06 17:22:50 +02:00
|
|
|
log.SetVerbose(GeneralConfig.Verbose)
|
2020-02-04 11:46:43 +02:00
|
|
|
return PrepareConfig(cmd, &metadata, "version", &stepConfig, config.OpenPiperFile)
|
2019-10-31 14:57:29 +02:00
|
|
|
},
|
2020-02-04 11:46:43 +02:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-01-31 15:06:08 +02:00
|
|
|
telemetryData := telemetry.CustomData{}
|
|
|
|
telemetryData.ErrorCode = "1"
|
|
|
|
handler := func() {
|
|
|
|
telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds())
|
|
|
|
telemetry.Send(&telemetryData)
|
|
|
|
}
|
|
|
|
log.DeferExitHandler(handler)
|
|
|
|
defer handler()
|
2020-01-29 14:17:54 +02:00
|
|
|
telemetry.Initialize(GeneralConfig.NoTelemetry, "version")
|
2020-02-04 11:46:43 +02:00
|
|
|
version(stepConfig, &telemetryData)
|
2020-01-31 15:06:08 +02:00
|
|
|
telemetryData.ErrorCode = "0"
|
2019-10-31 14:57:29 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:46:43 +02:00
|
|
|
addVersionFlags(createVersionCmd, &stepConfig)
|
2019-10-31 14:57:29 +02:00
|
|
|
return createVersionCmd
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:46:43 +02:00
|
|
|
func addVersionFlags(cmd *cobra.Command, stepConfig *versionOptions) {
|
2019-10-31 14:57:29 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve step metadata
|
|
|
|
func versionMetadata() config.StepData {
|
|
|
|
var theMetaData = config.StepData{
|
|
|
|
Spec: config.StepSpec{
|
|
|
|
Inputs: config.StepInputs{
|
|
|
|
Parameters: []config.StepParameters{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return theMetaData
|
|
|
|
}
|