|
1 | 1 | package php |
2 | 2 |
|
3 | 3 | import ( |
4 | | - `fmt` |
5 | | - `strings` |
6 | | - |
7 | 4 | core "dappco.re/go" |
8 | 5 | "dappco.re/go/cli/pkg/cli" |
9 | 6 | ) |
@@ -36,22 +33,22 @@ type phpCommandLine struct { |
36 | 33 | args []string |
37 | 34 | } |
38 | 35 |
|
39 | | -func phpFailure(format string, args ...any) error { // Result boundary |
40 | | - return fmt.Errorf(format, args...) |
| 36 | +func phpFailure(format string, args ...any) error { |
| 37 | + return core.E("php", core.Sprintf(format, args...), nil) |
41 | 38 | } |
42 | 39 |
|
43 | | -func phpWrapMessage(err error, message string) error { // Result boundary |
| 40 | +func phpWrapMessage(err error, message string) error { |
44 | 41 | if err == nil { |
45 | 42 | return nil |
46 | 43 | } |
47 | | - return fmt.Errorf("%s: %w", message, err) |
| 44 | + return core.E("php", message, err) |
48 | 45 | } |
49 | 46 |
|
50 | | -func phpWrapAction(err error, verb, subject string) error { // Result boundary |
| 47 | +func phpWrapAction(err error, verb, subject string) error { |
51 | 48 | if err == nil { |
52 | 49 | return nil |
53 | 50 | } |
54 | | - return fmt.Errorf("failed to %s %s: %w", verb, subject, err) |
| 51 | + return core.E("php", core.Sprintf("failed to %s %s", verb, subject), err) |
55 | 52 | } |
56 | 53 |
|
57 | 54 | func phpExit(code int, err error) error { // Result boundary |
@@ -177,35 +174,46 @@ func phpParseCommandLine(args []string) phpCommandLine { |
177 | 174 | } |
178 | 175 |
|
179 | 176 | func phpSplitFlag(arg string) (key, value string, hasValue bool, ok bool) { |
180 | | - if strings.HasPrefix(arg, "--") { |
181 | | - body := strings.TrimPrefix(arg, "--") |
| 177 | + if core.HasPrefix(arg, "--") { |
| 178 | + body := core.TrimPrefix(arg, "--") |
182 | 179 | if body == "" { |
183 | 180 | return "", "", false, false |
184 | 181 | } |
185 | | - key, value, hasValue = strings.Cut(body, "=") |
| 182 | + key, value, hasValue = phpCutOnEquals(body) |
186 | 183 | return key, value, hasValue, key != "" |
187 | 184 | } |
188 | 185 |
|
189 | | - if strings.HasPrefix(arg, "-") { |
190 | | - body := strings.TrimPrefix(arg, "-") |
| 186 | + if core.HasPrefix(arg, "-") { |
| 187 | + body := core.TrimPrefix(arg, "-") |
191 | 188 | if body == "" { |
192 | 189 | return "", "", false, false |
193 | 190 | } |
194 | | - key, value, hasValue = strings.Cut(body, "=") |
| 191 | + key, value, hasValue = phpCutOnEquals(body) |
195 | 192 | return key, value, hasValue, key != "" |
196 | 193 | } |
197 | 194 |
|
198 | 195 | return "", "", false, false |
199 | 196 | } |
200 | 197 |
|
| 198 | +// phpCutOnEquals splits "key=value" into (key, value, true) or returns |
| 199 | +// (s, "", false) when no `=` is present. Equivalent of strings.Cut(s, "=") |
| 200 | +// without importing strings. |
| 201 | +func phpCutOnEquals(s string) (key, value string, hasValue bool) { |
| 202 | + parts := core.SplitN(s, "=", 2) |
| 203 | + if len(parts) == 2 { |
| 204 | + return parts[0], parts[1], true |
| 205 | + } |
| 206 | + return s, "", false |
| 207 | +} |
| 208 | + |
201 | 209 | func (line phpCommandLine) Bool(name string, aliases ...string) bool { |
202 | 210 | keys := append([]string{name}, aliases...) |
203 | 211 | for _, key := range keys { |
204 | 212 | value, ok := line.flags[key] |
205 | 213 | if !ok { |
206 | 214 | continue |
207 | 215 | } |
208 | | - switch strings.ToLower(value) { |
| 216 | + switch core.Lower(value) { |
209 | 217 | case "", "1", "true", "yes", "on": |
210 | 218 | return true |
211 | 219 | default: |
|
0 commit comments