github.com/SamarSidharth/kpt@v0.0.0-20231122062228-c7d747ae3ace/commands/fn/fncmd.go (about)

     1  // Copyright 2019 The kpt Authors
     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 fn
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/GoogleContainerTools/kpt/commands/fn/doc"
    21  	"github.com/GoogleContainerTools/kpt/commands/fn/render"
    22  	"github.com/GoogleContainerTools/kpt/internal/docs/generated/fndocs"
    23  	"github.com/GoogleContainerTools/kpt/thirdparty/cmdconfig/commands/cmdeval"
    24  	"github.com/GoogleContainerTools/kpt/thirdparty/cmdconfig/commands/cmdsink"
    25  	"github.com/GoogleContainerTools/kpt/thirdparty/cmdconfig/commands/cmdsource"
    26  	"github.com/spf13/cobra"
    27  )
    28  
    29  func GetCommand(ctx context.Context, name string) *cobra.Command {
    30  	functions := &cobra.Command{
    31  		Use:     "fn",
    32  		Short:   fndocs.FnShort,
    33  		Long:    fndocs.FnLong,
    34  		Aliases: []string{"functions"},
    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  	functions.AddCommand(
    48  		cmdeval.EvalCommand(ctx, name),
    49  		render.NewCommand(ctx, name),
    50  		doc.NewCommand(ctx, name),
    51  		cmdsource.NewCommand(ctx, name),
    52  		cmdsink.NewCommand(ctx, name),
    53  	)
    54  	return functions
    55  }