mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-16 11:09:33 +02:00
81 lines
2.0 KiB
Plaintext
81 lines
2.0 KiB
Plaintext
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/config"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type testStepOptions struct {
|
|
Param0 string `json:"param0,omitempty"`
|
|
Param1 string `json:"param1,omitempty"`
|
|
Param2 string `json:"param2,omitempty"`
|
|
}
|
|
|
|
var myTestStepOptions testStepOptions
|
|
var testStepStepConfigJSON string
|
|
|
|
// TestStepCommand Test description
|
|
func TestStepCommand() *cobra.Command {
|
|
metadata := testStepMetadata()
|
|
var createTestStepCmd = &cobra.Command{
|
|
Use: "testStep",
|
|
Short: "Test description",
|
|
Long: `Long Test description`,
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
log.SetStepName("testStep")
|
|
log.SetVerbose(GeneralConfig.Verbose)
|
|
return PrepareConfig(cmd, &metadata, "testStep", &myTestStepOptions, OpenPiperFile)
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return testStep(myTestStepOptions)
|
|
},
|
|
}
|
|
|
|
addTestStepFlags(createTestStepCmd)
|
|
return createTestStepCmd
|
|
}
|
|
|
|
func addTestStepFlags(cmd *cobra.Command) {
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param0, "param0", "val0", "param0 description")
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param1, "param1", os.Getenv("PIPER_param1"), "param1 description")
|
|
cmd.Flags().StringVar(&myTestStepOptions.Param2, "param2", os.Getenv("PIPER_param2"), "param1 description")
|
|
|
|
cmd.MarkFlagRequired("param0")
|
|
cmd.MarkFlagRequired("param2")
|
|
}
|
|
|
|
// retrieve step metadata
|
|
func testStepMetadata() config.StepData {
|
|
var theMetaData = config.StepData{
|
|
Spec: config.StepSpec{
|
|
Inputs: config.StepInputs{
|
|
Parameters: []config.StepParameters{
|
|
{
|
|
Name: "param0",
|
|
Scope: []string{"GENERAL","PARAMETERS",},
|
|
Type: "string",
|
|
Mandatory: true,
|
|
},
|
|
{
|
|
Name: "param1",
|
|
Scope: []string{"PARAMETERS",},
|
|
Type: "string",
|
|
Mandatory: false,
|
|
},
|
|
{
|
|
Name: "param2",
|
|
Scope: []string{"PARAMETERS",},
|
|
Type: "string",
|
|
Mandatory: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
return theMetaData
|
|
}
|