mirror of
https://github.com/ko-build/ko.git
synced 2026-06-18 20:14:08 +02:00
warning users when using both --base-import-paths --bare flags (#618)
* warning users when using both --base-import-paths --bare flags Signed-off-by: Carlos Panato <ctadeu@gmail.com> * update header Signed-off-by: cpanato <ctadeu@gmail.com>
This commit is contained in:
@@ -82,6 +82,10 @@ func addApply(topLevel *cobra.Command) {
|
||||
ko apply -f config -- --namespace=foo --kubeconfig=cfg.yaml
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := options.Validate(po, bo); err != nil {
|
||||
return fmt.Errorf("validating options: %w", err)
|
||||
}
|
||||
|
||||
if !isKubectlAvailable() {
|
||||
return errors.New("error: kubectl is not available. kubectl must be installed to use ko apply")
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ func addBuild(topLevel *cobra.Command) {
|
||||
ko build --local github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := options.Validate(po, bo); err != nil {
|
||||
return fmt.Errorf("validating options: %w", err)
|
||||
}
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
bo.InsecureRegistry = po.InsecureRegistry
|
||||
|
||||
@@ -67,6 +67,10 @@ func addCreate(topLevel *cobra.Command) {
|
||||
ko apply -f config -- --namespace=foo --kubeconfig=cfg.yaml
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := options.Validate(po, bo); err != nil {
|
||||
return fmt.Errorf("validating options: %w", err)
|
||||
}
|
||||
|
||||
if !isKubectlAvailable() {
|
||||
return errors.New("error: kubectl is not available. kubectl must be installed to use ko create")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2022 Google LLC All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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 options
|
||||
|
||||
import "log"
|
||||
|
||||
const bareBaseFlagsWarning = `WARNING!
|
||||
-----------------------------------------------------------------
|
||||
Both --base-import-paths and --bare were set.
|
||||
|
||||
--base-import-paths will take precedence and ignore --bare flag.
|
||||
|
||||
In a future release this will be an error.
|
||||
-----------------------------------------------------------------
|
||||
`
|
||||
|
||||
func Validate(po *PublishOptions, bo *BuildOptions) error {
|
||||
if po.Bare && po.BaseImportPaths {
|
||||
log.Print(bareBaseFlagsWarning)
|
||||
// TODO: return error when we decided to make this an error, for now it is a warning
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -55,6 +55,10 @@ func addResolve(topLevel *cobra.Command) {
|
||||
ko resolve --local -f config/`,
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := options.Validate(po, bo); err != nil {
|
||||
return fmt.Errorf("validating options: %w", err)
|
||||
}
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
bo.InsecureRegistry = po.InsecureRegistry
|
||||
|
||||
@@ -49,6 +49,10 @@ func addRun(topLevel *cobra.Command) {
|
||||
# You can also supply args and flags to the command.
|
||||
ko run ./cmd/baz -- -v arg1 arg2 --yes`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := options.Validate(po, bo); err != nil {
|
||||
return fmt.Errorf("validating options: %w", err)
|
||||
}
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
// Args after -- are for kubectl, so only consider importPaths before it.
|
||||
|
||||
Reference in New Issue
Block a user