Add -o name for commands which use printer to output results

Added a new printer which prints 'resource/name' pair of a given
object.
This commit is contained in:
hurf
2015-08-18 15:35:35 +08:00
parent 00e34429e0
commit d2d96ff6e1
20 changed files with 138 additions and 26 deletions

View File

@@ -113,7 +113,7 @@ func NewDefaultRESTMapper(group string, versions []string, f VersionInterfacesFu
}
func (m *DefaultRESTMapper) Add(scope RESTScope, kind string, version string, mixedCase bool) {
plural, singular := kindToResource(kind, mixedCase)
plural, singular := KindToResource(kind, mixedCase)
m.plurals[singular] = plural
m.singulars[plural] = singular
meta := typeMeta{APIVersion: version, Kind: kind}
@@ -131,8 +131,8 @@ func (m *DefaultRESTMapper) Add(scope RESTScope, kind string, version string, mi
m.scopes[meta] = scope
}
// kindToResource converts Kind to a resource name.
func kindToResource(kind string, mixedCase bool) (plural, singular string) {
// KindToResource converts Kind to a resource name.
func KindToResource(kind string, mixedCase bool) (plural, singular string) {
if len(kind) == 0 {
return
}

View File

@@ -155,7 +155,7 @@ func TestKindToResource(t *testing.T) {
{Kind: "lowercases", MixedCase: false, Plural: "lowercases", Singular: "lowercases"},
}
for i, testCase := range testCases {
plural, singular := kindToResource(testCase.Kind, testCase.MixedCase)
plural, singular := KindToResource(testCase.Kind, testCase.MixedCase)
if singular != testCase.Singular || plural != testCase.Plural {
t.Errorf("%d: unexpected plural and singular: %s %s", i, plural, singular)
}