ParseInputDefinition parses an input definition from a map. This is a shared helper function that handles the common parsing logic for input definitions regardless of their source (safe-jobs, imports, etc.).
(inputConfig map[string]any)
| 21 | // This is a shared helper function that handles the common parsing logic |
| 22 | // for input definitions regardless of their source (safe-jobs, imports, etc.). |
| 23 | func ParseInputDefinition(inputConfig map[string]any) *InputDefinition { |
| 24 | input := &InputDefinition{} |
| 25 | |
| 26 | // Parse description |
| 27 | if desc, exists := inputConfig["description"]; exists { |
| 28 | if descStr, ok := desc.(string); ok { |
| 29 | input.Description = descStr |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Parse required |
| 34 | if req, exists := inputConfig["required"]; exists { |
| 35 | if reqBool, ok := req.(bool); ok { |
| 36 | input.Required = reqBool |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Parse default - supports string, number, or boolean |
| 41 | if def, exists := inputConfig["default"]; exists { |
| 42 | input.Default = def |
| 43 | } |
| 44 | |
| 45 | // Parse type |
| 46 | if typ, exists := inputConfig["type"]; exists { |
| 47 | if typStr, ok := typ.(string); ok { |
| 48 | input.Type = typStr |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Parse options (for choice type) |
| 53 | if opts, exists := inputConfig["options"]; exists { |
| 54 | if optsList, ok := opts.([]any); ok { |
| 55 | for _, opt := range optsList { |
| 56 | if optStr, ok := opt.(string); ok { |
| 57 | input.Options = append(input.Options, optStr) |
| 58 | } |
| 59 | } |
| 60 | } else if optsStr, ok := opts.([]string); ok { |
| 61 | input.Options = optsStr |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | inputsLog.Printf("Parsed input definition: type=%s, required=%t, options=%d", input.Type, input.Required, len(input.Options)) |
| 66 | return input |
| 67 | } |
| 68 | |
| 69 | // ParseInputDefinitions parses a map of input definitions from a frontmatter map. |
| 70 | // Returns a map of input name to InputDefinition. |