Merge pull request #90789 from hezhizhen/kubectl_cp

Refine extractFileSpec
This commit is contained in:
Kubernetes Prow Robot 2020-06-15 08:09:56 -07:00 committed by GitHub
commit 0535c11381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,29 +127,34 @@ 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 {
return fileSpec{}, errFileSpecDoesntMatchFormat
}
pod, file := arg[:i], arg[i+1:]
pieces := strings.Split(pod, "/") pieces := strings.Split(pod, "/")
if len(pieces) == 1 { switch len(pieces) {
case 1:
return fileSpec{ return fileSpec{
PodName: pieces[0], PodName: pieces[0],
File: file, File: file,
}, nil }, nil
} case 2:
if len(pieces) == 2 {
return fileSpec{ return fileSpec{
PodNamespace: pieces[0], PodNamespace: pieces[0],
PodName: pieces[1], PodName: pieces[1],
File: file, File: file,
}, nil }, nil
} default:
}
return fileSpec{}, errFileSpecDoesntMatchFormat return fileSpec{}, errFileSpecDoesntMatchFormat
} }
}
// Complete completes all the required options // Complete completes all the required options
func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {