github.com/awslabs/clencli@v0.0.0-20210514234156-7ecf17182a20/cobra/controller/root.go (about)

     1  /*
     2  Copyright © 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     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  
    16  package controller
    17  
    18  import (
    19  	"fmt"
    20  	"os"
    21  
    22  	"github.com/awslabs/clencli/helper"
    23  	"github.com/spf13/cobra"
    24  )
    25  
    26  var profile string
    27  
    28  // RootCmd represents the base command when called without any subcommands
    29  func RootCmd() *cobra.Command {
    30  	man, err := helper.GetManual("root")
    31  	if err != nil {
    32  		fmt.Println(err)
    33  		os.Exit(1)
    34  	}
    35  
    36  	cmd := &cobra.Command{
    37  		Use:   man.Use,
    38  		Short: man.Short,
    39  		Long:  man.Long,
    40  	}
    41  
    42  	// Here you will define your flags and configuration settings.
    43  	// Cobra supports persistent flags, which, if defined here will be global for your application.
    44  	cmd.PersistentFlags().StringVarP(&profile, "profile", "p", "default", "Use a specific profile from your credentials and configurations file.")
    45  
    46  	// TODO: allow users to pass their prefer location for clencli's configurations directory
    47  
    48  	return cmd
    49  }