mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Refine extractFileSpec
This commit is contained in:
parent
4d813c1360
commit
1c84efe0c7
@ -127,28 +127,33 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func extractFileSpec(arg string) (fileSpec, error) {
|
func extractFileSpec(arg string) (fileSpec, error) {
|
||||||
if i := strings.Index(arg, ":"); i == -1 {
|
i := strings.Index(arg, ":")
|
||||||
|
|
||||||
|
if i == -1 {
|
||||||
return fileSpec{File: arg}, nil
|
return fileSpec{File: arg}, nil
|
||||||
} else if i > 0 {
|
}
|
||||||
file := arg[i+1:]
|
// filespec starting with a semicolon is invalid
|
||||||
pod := arg[:i]
|
if i == 0 {
|
||||||
pieces := strings.Split(pod, "/")
|
return fileSpec{}, errFileSpecDoesntMatchFormat
|
||||||
if len(pieces) == 1 {
|
|
||||||
return fileSpec{
|
|
||||||
PodName: pieces[0],
|
|
||||||
File: file,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
if len(pieces) == 2 {
|
|
||||||
return fileSpec{
|
|
||||||
PodNamespace: pieces[0],
|
|
||||||
PodName: pieces[1],
|
|
||||||
File: file,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileSpec{}, errFileSpecDoesntMatchFormat
|
pod, file := arg[:i], arg[i+1:]
|
||||||
|
pieces := strings.Split(pod, "/")
|
||||||
|
switch len(pieces) {
|
||||||
|
case 1:
|
||||||
|
return fileSpec{
|
||||||
|
PodName: pieces[0],
|
||||||
|
File: file,
|
||||||
|
}, nil
|
||||||
|
case 2:
|
||||||
|
return fileSpec{
|
||||||
|
PodNamespace: pieces[0],
|
||||||
|
PodName: pieces[1],
|
||||||
|
File: file,
|
||||||
|
}, nil
|
||||||
|
default:
|
||||||
|
return fileSpec{}, errFileSpecDoesntMatchFormat
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete completes all the required options
|
// Complete completes all the required options
|
||||||
|
Loading…
Reference in New Issue
Block a user