refactor getting uninitialized in kubectl get

This commit is contained in:
Di Xu 2017-12-07 13:30:20 +08:00
parent f875ee596d
commit d66d8f053d

View File

@ -65,6 +65,8 @@ type GetOptions struct {
ShowKind bool ShowKind bool
LabelColumns []string LabelColumns []string
Export bool Export bool
IncludeUninitialized bool
} }
var ( var (
@ -190,9 +192,13 @@ func (options *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
options.ExplicitNamespace = false options.ExplicitNamespace = false
} }
options.IncludeUninitialized = cmdutil.ShouldIncludeUninitialized(cmd, false)
switch { switch {
case options.Watch || options.WatchOnly: case options.Watch || options.WatchOnly:
// include uninitialized objects when watching on a single object
// unless explicitly set --include-uninitialized=false
options.IncludeUninitialized = cmdutil.ShouldIncludeUninitialized(cmd, len(args) == 2)
default: default:
if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(options.Filenames) { if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(options.Filenames) {
fmt.Fprint(options.ErrOut, "You must specify the type of resource to get. ", cmdutil.ValidResourceTypeList(f)) fmt.Fprint(options.ErrOut, "You must specify the type of resource to get. ", cmdutil.ValidResourceTypeList(f))
@ -240,7 +246,7 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str
FieldSelectorParam(options.FieldSelector). FieldSelectorParam(options.FieldSelector).
ExportParam(options.Export). ExportParam(options.Export).
RequestChunksOf(options.ChunkSize). RequestChunksOf(options.ChunkSize).
IncludeUninitialized(cmdutil.ShouldIncludeUninitialized(cmd, false)). // TODO: this needs to be better factored IncludeUninitialized(options.IncludeUninitialized).
ResourceTypeOrNameArgs(true, args...). ResourceTypeOrNameArgs(true, args...).
ContinueOnError(). ContinueOnError().
Latest(). Latest().
@ -442,11 +448,6 @@ func (options *GetOptions) raw(f cmdutil.Factory) error {
// watch starts a client-side watch of one or more resources. // watch starts a client-side watch of one or more resources.
// TODO: remove the need for arguments here. // TODO: remove the need for arguments here.
func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) error { func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
// TODO: this could be better factored
// include uninitialized objects when watching on a single object
// unless explicitly set --include-uninitialized=false
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, len(args) == 2)
r := f.NewBuilder(). r := f.NewBuilder().
Unstructured(). Unstructured().
NamespaceParam(options.Namespace).DefaultNamespace().AllNamespaces(options.AllNamespaces). NamespaceParam(options.Namespace).DefaultNamespace().AllNamespaces(options.AllNamespaces).
@ -455,7 +456,7 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s
FieldSelectorParam(options.FieldSelector). FieldSelectorParam(options.FieldSelector).
ExportParam(options.Export). ExportParam(options.Export).
RequestChunksOf(options.ChunkSize). RequestChunksOf(options.ChunkSize).
IncludeUninitialized(includeUninitialized). IncludeUninitialized(options.IncludeUninitialized).
ResourceTypeOrNameArgs(true, args...). ResourceTypeOrNameArgs(true, args...).
SingleResourceType(). SingleResourceType().
Latest(). Latest().