Add --dry option to view the generated spec without saving (#1504)
This commit is contained in:
@@ -31,7 +31,7 @@ func Commands() *cobra.Command {
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.KwFnName},
|
||||
Optional: []flag.Flag{flag.KwName, flag.KwObjType, flag.KwNamespace, flag.NamespaceFunction, flag.SpecSave},
|
||||
Optional: []flag.Flag{flag.KwName, flag.KwObjType, flag.KwNamespace, flag.NamespaceFunction, flag.SpecSave, flag.SpecDry},
|
||||
// TODO: add label selector flag
|
||||
// flag.KwLabelsFlag
|
||||
})
|
||||
|
||||
@@ -103,11 +103,16 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
// if we're writing a spec, don't call the API
|
||||
// save to spec file or display the spec to console
|
||||
if input.Bool(flagkey.SpecDry) {
|
||||
return spec.SpecDry(*opts.watcher)
|
||||
}
|
||||
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specFile := fmt.Sprintf("kubewatch-%v.yaml", opts.watcher.ObjectMeta.Name)
|
||||
err := spec.SpecSave(*opts.watcher, specFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating kubewatch spec")
|
||||
return errors.Wrap(err, "error saving kubewatch spec")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user