github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/commands/pkg/pkgcmd.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 pkg
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/GoogleContainerTools/kpt/commands/pkg/diff"
    21  	"github.com/GoogleContainerTools/kpt/commands/pkg/get"
    22  	initialization "github.com/GoogleContainerTools/kpt/commands/pkg/init"
    23  	"github.com/GoogleContainerTools/kpt/commands/pkg/update"
    24  	"github.com/GoogleContainerTools/kpt/internal/docs/generated/pkgdocs"
    25  	"github.com/GoogleContainerTools/kpt/thirdparty/cmdconfig/commands/cmdtree"
    26  	"github.com/spf13/cobra"
    27  )
    28  
    29  func GetCommand(ctx context.Context, name string) *cobra.Command {
    30  	pkg := &cobra.Command{
    31  		Use:     "pkg",
    32  		Short:   pkgdocs.PkgShort,
    33  		Long:    pkgdocs.PkgLong,
    34  		Aliases: []string{"package"},
    35  		RunE: func(cmd *cobra.Command, args []string) error {
    36  			h, err := cmd.Flags().GetBool("help")
    37  			if err != nil {
    38  				return err
    39  			}
    40  			if h {
    41  				return cmd.Help()
    42  			}
    43  			return cmd.Usage()
    44  		},
    45  	}
    46  
    47  	pkg.AddCommand(
    48  		get.NewCommand(ctx, name), initialization.NewCommand(ctx, name),
    49  		update.NewCommand(ctx, name), diff.NewCommand(ctx, name),
    50  		cmdtree.NewCommand(ctx, name),
    51  	)
    52  	return pkg
    53  }