airshipctl/cmd/document/document.go
Matt McEuen 6af3da8d7b Remove config file requirement for plugin command
Change 725820 [1] configured airshipctl to fail an airship config file
isn't present.  The present change makes an exception to that behavior
for the document plugin subcommand, and moves the plugin loading from
the parent document command into the pull subcommand.

There are multiple reasons we don't want config enforcement in place for plugins:

- If a non-standard config file location is configured via an environment variable,
  the plugin won't know about it (since it's invoked separately by kustomize), and it
  would look for a potentially non-existant default config file, and fail.

- If a user is using the kustomize cli by hand along with airshipctl plugins
  (as opposed to driving the process via airshipctl itself), then they do not
  need the config anyway -- the plugin subcommand doesn't actually use it.
  Forcing the user to create a config file seems awkward here.

[1]: https://review.opendev.org/#/c/725820/16

Change-Id: Ic1b652efb14439ed2757eb9fb0a86feb8b3ef21c
2020-06-22 21:32:18 -05:00

41 lines
1.3 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package document
import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/log"
)
// NewDocumentCommand creates a new command for managing airshipctl documents
func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
documentRootCmd := &cobra.Command{
Use: "document",
Short: "Manage deployment documents",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Note: config is not loaded here; the kustomize plugin command doesn't
// require it, and multiple use cases fail if we assume the file is there.
log.Init(rootSettings.Debug, cmd.OutOrStderr())
},
}
documentRootCmd.AddCommand(NewPullCommand(rootSettings, true))
documentRootCmd.AddCommand(NewPluginCommand(rootSettings))
return documentRootCmd
}