Implement number flags
This commit is contained in:
parent
30d0afe43f
commit
c3742ade4e
6 changed files with 104 additions and 5 deletions
|
@ -46,6 +46,9 @@ type myTeamFlag struct {
|
|||
Justify bool `json:"justify,omitempty"`
|
||||
Choices map[string]interface{} `json:"choices,omitempty"`
|
||||
ChoicesCost int64 `json:"choices_cost,omitempty"`
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
Step *float64 `json:"step,omitempty"`
|
||||
}
|
||||
type myTeamMCQJustifiedChoice struct {
|
||||
Label string `json:"label"`
|
||||
|
@ -204,6 +207,39 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
Help: k.Help,
|
||||
}
|
||||
|
||||
if strings.HasPrefix(flag.Type, "number") {
|
||||
fields := strings.Split(flag.Type, ",")
|
||||
if len(fields) == 4 {
|
||||
flag.Type = fields[0]
|
||||
|
||||
var tmp_min, tmp_max, tmp_step float64
|
||||
|
||||
if len(fields[1]) > 0 {
|
||||
tmp_min, err = strconv.ParseFloat(fields[1], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Min = &tmp_min
|
||||
}
|
||||
|
||||
if len(fields[2]) > 0 {
|
||||
tmp_max, err = strconv.ParseFloat(fields[2], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Max = &tmp_max
|
||||
}
|
||||
|
||||
if len(fields[3]) > 0 {
|
||||
tmp_step, err = strconv.ParseFloat(fields[3], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Step = &tmp_step
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve solved state or solution for public iface
|
||||
if t == nil {
|
||||
flag.IgnoreCase = k.IgnoreCase
|
||||
|
|
Reference in a new issue