ArgToOption takes two candidate strings and returns a tuple consisting of what type of option the strings define, the value of the option, how many of the strings it took to extract the option value, and a nillable error.
(opt string, next string)
| 65 | // what type of option the strings define, the value of the option, how many |
| 66 | // of the strings it took to extract the option value, and a nillable error. |
| 67 | func ArgToOption(opt string, next string) (OptionType, string, int, error) { |
| 68 | patternStandaloneA := regexp.MustCompile(`^-(a|-arg)$`) |
| 69 | patternStandaloneB := regexp.MustCompile(`^-(b|-build-arg)$`) |
| 70 | patternStandaloneI := regexp.MustCompile(`^-(i|-include)$`) |
| 71 | patternStandaloneM := regexp.MustCompile(`^-(m|-image)$`) |
| 72 | patternStandaloneE := regexp.MustCompile(`^-(e|-extension)$`) |
| 73 | patternStandaloneC := regexp.MustCompile(`^-C$`) |
| 74 | patternCombinationA := regexp.MustCompile(`^--arg=(.+)$`) |
| 75 | patternCombinationB := regexp.MustCompile(`^--build-arg=(.+)$`) |
| 76 | patternCombinationI := regexp.MustCompile(`^--include=(.+)$`) |
| 77 | patternCombinationM := regexp.MustCompile(`^--image=(.+)$`) |
| 78 | patternCombinationE := regexp.MustCompile(`^--extension=(.+)$`) |
| 79 | patternSource := regexp.MustCompile(`^[^-_].*\..+`) |
| 80 | patternUpdateFlag := regexp.MustCompile(`^-(-update|u)$`) |
| 81 | patternHelpFlag := regexp.MustCompile(`^-(-help|h)$`) |
| 82 | patternVersionFlag := regexp.MustCompile(`^-(-version|v)$`) |
| 83 | patternCleanFlag := regexp.MustCompile(`^--clean$`) |
| 84 | |
| 85 | switch { |
| 86 | case patternStandaloneA.FindStringIndex(opt) != nil: |
| 87 | return Arg, next, 2, nil |
| 88 | case patternStandaloneB.FindStringIndex(opt) != nil: |
| 89 | return BuildArg, next, 2, nil |
| 90 | case patternStandaloneI.FindStringIndex(opt) != nil: |
| 91 | return Include, next, 2, nil |
| 92 | case patternStandaloneM.FindStringIndex(opt) != nil: |
| 93 | return Image, next, 2, nil |
| 94 | case patternStandaloneE.FindStringIndex(opt) != nil: |
| 95 | return Extension, next, 2, nil |
| 96 | case patternStandaloneC.FindStringIndex(opt) != nil: |
| 97 | return TargetDir, next, 2, nil |
| 98 | case patternCombinationA.FindStringIndex(opt) != nil: |
| 99 | return Arg, patternCombinationA.FindStringSubmatch(opt)[1], 1, nil |
| 100 | case patternCombinationB.FindStringIndex(opt) != nil: |
| 101 | return BuildArg, patternCombinationB.FindStringSubmatch(opt)[1], 1, nil |
| 102 | case patternCombinationI.FindStringIndex(opt) != nil: |
| 103 | return Include, patternCombinationI.FindStringSubmatch(opt)[1], 1, nil |
| 104 | case patternCombinationM.FindStringIndex(opt) != nil: |
| 105 | return Image, patternCombinationM.FindStringSubmatch(opt)[1], 1, nil |
| 106 | case patternCombinationE.FindStringIndex(opt) != nil: |
| 107 | return Extension, patternCombinationE.FindStringSubmatch(opt)[1], 1, nil |
| 108 | case patternUpdateFlag.FindStringIndex(opt) != nil: |
| 109 | return UpdateFlag, "", 1, nil |
| 110 | case patternHelpFlag.FindStringIndex(opt) != nil: |
| 111 | return HelpFlag, "", 1, nil |
| 112 | case patternVersionFlag.FindStringIndex(opt) != nil: |
| 113 | return VersionFlag, "", 1, nil |
| 114 | case patternCleanFlag.FindStringIndex(opt) != nil: |
| 115 | return CleanFlag, "", 1, nil |
| 116 | case patternSource.FindStringIndex(opt) != nil: |
| 117 | return Source, opt, 1, nil |
| 118 | default: |
| 119 | return None, "", 0, fmt.Errorf("Unknown option: %s", opt) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // ParseArgs take a string slice comprised of sources, includes, flags, switches |
| 124 | // and their values and returns a map of these types to a string slice |
no outgoing calls