Skip to content

Commit

Permalink
warning users when using both --base-import-paths --bare flags (#618)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
cpanato authored Feb 28, 2022
1 parent ea93812 commit 62800bc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/commands/options/validate.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions pkg/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 62800bc

Please sign in to comment.