File tree Expand file tree Collapse file tree 1 file changed +25
-20
lines changed Expand file tree Collapse file tree 1 file changed +25
-20
lines changed Original file line number Diff line number Diff line change @@ -127,28 +127,33 @@ var (
127
127
)
128
128
129
129
func extractFileSpec (arg string ) (fileSpec , error ) {
130
- if i := strings .Index (arg , ":" ); i == - 1 {
130
+ i := strings .Index (arg , ":" )
131
+
132
+ if i == - 1 {
131
133
return fileSpec {File : arg }, nil
132
- } else if i > 0 {
133
- file := arg [i + 1 :]
134
- pod := arg [:i ]
135
- pieces := strings .Split (pod , "/" )
136
- if len (pieces ) == 1 {
137
- return fileSpec {
138
- PodName : pieces [0 ],
139
- File : file ,
140
- }, nil
141
- }
142
- if len (pieces ) == 2 {
143
- return fileSpec {
144
- PodNamespace : pieces [0 ],
145
- PodName : pieces [1 ],
146
- File : file ,
147
- }, nil
148
- }
149
134
}
150
-
151
- return fileSpec {}, errFileSpecDoesntMatchFormat
135
+ // filespec starting with a semicolon is invalid
136
+ if i == 0 {
137
+ return fileSpec {}, errFileSpecDoesntMatchFormat
138
+ }
139
+
140
+ pod , file := arg [:i ], arg [i + 1 :]
141
+ pieces := strings .Split (pod , "/" )
142
+ switch len (pieces ) {
143
+ case 1 :
144
+ return fileSpec {
145
+ PodName : pieces [0 ],
146
+ File : file ,
147
+ }, nil
148
+ case 2 :
149
+ return fileSpec {
150
+ PodNamespace : pieces [0 ],
151
+ PodName : pieces [1 ],
152
+ File : file ,
153
+ }, nil
154
+ default :
155
+ return fileSpec {}, errFileSpecDoesntMatchFormat
156
+ }
152
157
}
153
158
154
159
// Complete completes all the required options
You can’t perform that action at this time.
0 commit comments