Skip to content

Commit 493a75e

Browse files
leodidofntlnz
authored andcommitted
feat(cmd/pkg): run methods for get and run commands
Signed-off-by: Leonardo Di Donato <[email protected]>
1 parent 7627b94 commit 493a75e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

pkg/cmd/get.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/fntlnz/kubectl-trace/pkg/factory"
77
"github.com/spf13/cobra"
88
"k8s.io/cli-runtime/pkg/genericclioptions"
9-
// "k8s.io/kubernetes/pkg/kubectl/util/templates"
109
)
1110

1211
var (
@@ -74,6 +73,9 @@ func NewGetCommand(factory factory.Factory, streams genericclioptions.IOStreams)
7473
if err := o.Complete(factory, c, args); err != nil {
7574
return err
7675
}
76+
if err := o.Run(); err != nil {
77+
return err
78+
}
7779
return nil
7880
},
7981
}
@@ -100,16 +102,29 @@ func (o *GetOptions) Validate(cmd *cobra.Command, args []string) error {
100102

101103
// Complete completes the setup of the command.
102104
func (o *GetOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
105+
var err error
103106
o.namespace, o.explicitNamespace, _ = factory.ToRawKubeConfigLoader().Namespace()
107+
if err != nil {
108+
return err
109+
}
104110

111+
// All namespaces, when present, overrides namespace flag
105112
if cmd.Flag("all-namespaces").Changed {
106113
o.allNamespaces = *o.ResourceBuilderFlags.AllNamespaces
107114
o.explicitNamespace = false
108115
o.namespace = ""
109116
}
117+
// Need either a namespace, a trace ID, or all namespaces
110118
if o.traceArg == "" && !o.allNamespaces && !o.explicitNamespace {
111119
return fmt.Errorf(missingTargetErr)
112120
}
113121

122+
// todo > init printers (need PrintFlags)
123+
124+
return nil
125+
}
126+
127+
// Run executes the get command.
128+
func (o *GetOptions) Run() error {
114129
return nil
115130
}

pkg/cmd/run.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams)
7070
if err := o.Complete(factory, c, args); err != nil {
7171
return err
7272
}
73+
if err := o.Run(); err != nil {
74+
return err
75+
}
7376
return nil
7477
},
7578
}
@@ -122,12 +125,23 @@ func (o *RunOptions) Validate(cmd *cobra.Command, args []string) error {
122125

123126
// Complete completes the setup of the command.
124127
func (o *RunOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error {
125-
o.namespace, o.explicitNamespace, _ = factory.ToRawKubeConfigLoader().Namespace()
128+
var err error
129+
o.namespace, o.explicitNamespace, err = factory.ToRawKubeConfigLoader().Namespace()
130+
if err != nil {
131+
return err
132+
}
126133

127134
spew.Dump(o)
135+
b := factory.NewBuilder()
136+
spew.Dump(b)
128137

129-
// get resource by pof | type/name
138+
// get resource by pod | type/name
130139
// get container
131140

132141
return nil
133142
}
143+
144+
// Run executes the run command.
145+
func (o *RunOptions) Run() error {
146+
return nil
147+
}

0 commit comments

Comments
 (0)