github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/commands/commands.go (about)

     1  // Copyright 2019 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package commands
    16  
    17  import (
    18  	"context"
    19  	"strings"
    20  
    21  	"github.com/GoogleContainerTools/kpt/commands/alpha"
    22  	"github.com/GoogleContainerTools/kpt/commands/fn"
    23  	"github.com/GoogleContainerTools/kpt/commands/live"
    24  	"github.com/GoogleContainerTools/kpt/commands/pkg"
    25  	"github.com/spf13/cobra"
    26  )
    27  
    28  // NormalizeCommand will modify commands to be consistent, e.g. silencing errors
    29  func NormalizeCommand(c ...*cobra.Command) {
    30  	for _, cmd := range c {
    31  		cmd.Short = strings.TrimPrefix(cmd.Short, "[Alpha] ")
    32  		NormalizeCommand(cmd.Commands()...)
    33  	}
    34  }
    35  
    36  // GetKptCommands returns the set of kpt commands to be registered
    37  func GetKptCommands(ctx context.Context, name, version string) []*cobra.Command {
    38  	var c []*cobra.Command
    39  	fnCmd := fn.GetCommand(ctx, name)
    40  	pkgCmd := pkg.GetCommand(ctx, name)
    41  	liveCmd := live.GetCommand(ctx, name, version)
    42  	alphaCmd := alpha.GetCommand(ctx, name, version)
    43  
    44  	c = append(c, pkgCmd, fnCmd, liveCmd, alphaCmd)
    45  
    46  	// apply cross-cutting issues to commands
    47  	NormalizeCommand(c...)
    48  	return c
    49  }