update resource builder error message to be more clear

This commit is contained in:
juanvallejo 2016-07-07 15:22:42 -04:00
parent 4da14c8a64
commit 17a4df2c31
2 changed files with 8 additions and 3 deletions

View File

@ -333,7 +333,7 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
} }
case len(args) == 0: case len(args) == 0:
default: default:
b.errs = append(b.errs, fmt.Errorf("when passing arguments, must be resource or resource and name")) b.errs = append(b.errs, fmt.Errorf("arguments must consist of a resource or a resource and name"))
} }
return b return b
} }
@ -362,7 +362,12 @@ func hasCombinedTypeArgs(args []string) (bool, error) {
case hasSlash > 0 && hasSlash == len(args): case hasSlash > 0 && hasSlash == len(args):
return true, nil return true, nil
case hasSlash > 0 && hasSlash != len(args): case hasSlash > 0 && hasSlash != len(args):
return true, fmt.Errorf("when passing arguments in resource/name form, all arguments must include the resource") baseCmd := "cmd"
if len(os.Args) > 0 {
baseCmdSlice := strings.Split(os.Args[0], "/")
baseCmd = baseCmdSlice[len(baseCmdSlice)-1]
}
return true, fmt.Errorf("there is no need to specify a resource type as a separate argument when passing arguments in resource/name form (e.g. '%s get resource/<resource_name>' instead of '%s get resource resource/<resource_name>'", baseCmd, baseCmd)
default: default:
return false, nil return false, nil
} }

View File

@ -1231,7 +1231,7 @@ func TestHasNames(t *testing.T) {
{ {
args: []string{"rc/foo", "bar"}, args: []string{"rc/foo", "bar"},
expectedHasName: false, expectedHasName: false,
expectedError: fmt.Errorf("when passing arguments in resource/name form, all arguments must include the resource"), expectedError: fmt.Errorf("there is no need to specify a resource type as a separate argument when passing arguments in resource/name form (e.g. 'resource.test get resource/<resource_name>' instead of 'resource.test get resource resource/<resource_name>'"),
}, },
} }
for _, test := range tests { for _, test := range tests {