OLD | NEW |
1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package python | 5 package python |
6 | 6 |
7 import ( | 7 import ( |
8 "strings" | 8 "strings" |
9 "unicode/utf8" | 9 "unicode/utf8" |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // "-" instructs Python to load the script from STDIN. | 97 // "-" instructs Python to load the script from STDIN. |
98 cmd.Target = ScriptTarget{ | 98 cmd.Target = ScriptTarget{ |
99 Path: "-", | 99 Path: "-", |
100 } | 100 } |
101 break | 101 break |
102 } | 102 } |
103 | 103 |
104 // Extract the flag Target. -f<lag> | 104 // Extract the flag Target. -f<lag> |
105 r, l := utf8.DecodeRuneInString(flag) | 105 r, l := utf8.DecodeRuneInString(flag) |
106 if r == utf8.RuneError { | 106 if r == utf8.RuneError { |
107 » » » err = errors.Reason("invalid rune in flag #%(index)d").D
("index", i).Err() | 107 » » » err = errors.Reason("invalid rune in flag #%d", i).Err() |
108 return | 108 return |
109 } | 109 } |
110 | 110 |
111 // Is this a combined flag/value (e.g., -c'paoskdpo') ? | 111 // Is this a combined flag/value (e.g., -c'paoskdpo') ? |
112 flag = flag[l:] | 112 flag = flag[l:] |
113 twoVarType := func() (string, error) { | 113 twoVarType := func() (string, error) { |
114 if len(flag) > 0 { | 114 if len(flag) > 0 { |
115 return flag, nil | 115 return flag, nil |
116 } | 116 } |
117 | 117 |
118 if i >= len(args) { | 118 if i >= len(args) { |
119 » » » » return "", errors.Reason("two-value flag -%(flag
)c missing second value at %(index)d"). | 119 » » » » return "", errors.Reason("two-value flag -%c mis
sing second value at %d", r, i).Err() |
120 » » » » » D("flag", r). | |
121 » » » » » D("index", i). | |
122 » » » » » Err() | |
123 } | 120 } |
124 | 121 |
125 value := args[i] | 122 value := args[i] |
126 i++ | 123 i++ |
127 return value, nil | 124 return value, nil |
128 } | 125 } |
129 | 126 |
130 switch r { | 127 switch r { |
131 // Two-variable execution flags. | 128 // Two-variable execution flags. |
132 case 'c': | 129 case 'c': |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 cmd.Args = args[i:] | 168 cmd.Args = args[i:] |
172 return | 169 return |
173 } | 170 } |
174 | 171 |
175 func trimPrefix(v, pfx string) (string, bool) { | 172 func trimPrefix(v, pfx string) (string, bool) { |
176 if strings.HasPrefix(v, pfx) { | 173 if strings.HasPrefix(v, pfx) { |
177 return v[len(pfx):], true | 174 return v[len(pfx):], true |
178 } | 175 } |
179 return v, false | 176 return v, false |
180 } | 177 } |
OLD | NEW |