Make kubectl commands return errors and centralize exit handling
This commit is contained in:
@@ -33,20 +33,35 @@ func (f *Factory) NewCmdDescribe(out io.Writer) *cobra.Command {
|
||||
This command joins many API calls together to form a detailed description of a
|
||||
given resource.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdNamespace, err := f.DefaultNamespace(cmd)
|
||||
err := RunDescribe(f, out, cmd, args)
|
||||
util.CheckErr(err)
|
||||
|
||||
mapper, _ := f.Object(cmd)
|
||||
// TODO: use resource.Builder instead
|
||||
mapping, namespace, name := util.ResourceFromArgs(cmd, args, mapper, cmdNamespace)
|
||||
|
||||
describer, err := f.Describer(cmd, mapping)
|
||||
util.CheckErr(err)
|
||||
|
||||
s, err := describer.Describe(namespace, name)
|
||||
util.CheckErr(err)
|
||||
fmt.Fprintf(out, "%s\n", s)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func RunDescribe(f *Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
||||
cmdNamespace, err := f.DefaultNamespace(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mapper, _ := f.Object(cmd)
|
||||
// TODO: use resource.Builder instead
|
||||
mapping, namespace, name, err := util.ResourceFromArgs(cmd, args, mapper, cmdNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
describer, err := f.Describer(cmd, mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := describer.Describe(namespace, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", s)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user