mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-16 11:09:33 +02:00
cbe368fe36
* Added base functionality for checkmarx interaction * Extend http client with file upload capabilities * Latest changes * Add debug logging * Introduce Uploader interface * Add tests for checkmarx client * Hook new checkmarx command * Improve coverage * Add tests * Improved test coverage and fixed code * Add influx reporting * Add alternation capabilities * Add groovy step * Try fix cmd * Enhancements * Fix report generation * Final performance improvements * Fix code * Structure code, cleanup * Improvements * Fix codeclimate issue * Update groovy * Adapt latest changes to http * Fix test * Fix http tests * Fix test * Fix test * Fix test 2 * Fix code * Fix code 2 * Fix code * Code * Fix * Fix * Add report and link handling * Fix returns, add groovy test * Review comments * Added doc template * Docs update * Remove SAP internals * Better status display * Add name to link * Fix test * Fix * Fix verbose handling * Fix verbose handling 2 * Fix verbose handling 3 * Fix * Tiny improvements * Regenerate * Fix test * Fix test code * Fix verbosity issue * Fix test * Fix test * Fix test
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
flag "github.com/spf13/pflag"
|
|
)
|
|
|
|
// AvailableFlagValues returns all flags incl. values which are available to the command.
|
|
func AvailableFlagValues(cmd *cobra.Command, filters *StepFilters) map[string]interface{} {
|
|
flagValues := map[string]interface{}{}
|
|
flags := cmd.Flags()
|
|
//only check flags where value has been set
|
|
flags.Visit(func(pflag *flag.Flag) {
|
|
|
|
switch pflag.Value.Type() {
|
|
case "string":
|
|
flagValues[pflag.Name] = pflag.Value.String()
|
|
case "stringSlice":
|
|
flagValues[pflag.Name], _ = flags.GetStringSlice(pflag.Name)
|
|
case "bool":
|
|
flagValues[pflag.Name], _ = flags.GetBool(pflag.Name)
|
|
case "int":
|
|
flagValues[pflag.Name], _ = flags.GetInt(pflag.Name)
|
|
default:
|
|
fmt.Printf("Meta data type not set or not known: '%v'\n", pflag.Value.Type())
|
|
os.Exit(1)
|
|
}
|
|
filters.Parameters = append(filters.Parameters, pflag.Name)
|
|
})
|
|
return flagValues
|
|
}
|
|
|
|
// MarkFlagsWithValue marks a flag as changed if value is available for the flag through the step configuration.
|
|
func MarkFlagsWithValue(cmd *cobra.Command, stepConfig StepConfig) {
|
|
flags := cmd.Flags()
|
|
flags.VisitAll(func(pflag *flag.Flag) {
|
|
//mark as available in case default is available or config is available
|
|
if len(pflag.Value.String()) > 0 || stepConfig.Config[pflag.Name] != nil {
|
|
pflag.Changed = true
|
|
}
|
|
})
|
|
}
|