xref: /aosp_15_r20/external/bazelbuild-rules_go/examples/basic-gazelle/cmd/root.go (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1*9bb1b549SSpandan Das// Copyright 2022 The Bazel Authors. All rights reserved.
2*9bb1b549SSpandan Das//
3*9bb1b549SSpandan Das// Licensed under the Apache License, Version 2.0 (the "License");
4*9bb1b549SSpandan Das// you may not use this file except in compliance with the License.
5*9bb1b549SSpandan Das// You may obtain a copy of the License at
6*9bb1b549SSpandan Das//
7*9bb1b549SSpandan Das//      http://www.apache.org/licenses/LICENSE-2.0
8*9bb1b549SSpandan Das//
9*9bb1b549SSpandan Das// Unless required by applicable law or agreed to in writing, software
10*9bb1b549SSpandan Das// distributed under the License is distributed on an "AS IS" BASIS,
11*9bb1b549SSpandan Das// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9bb1b549SSpandan Das// See the License for the specific language governing permissions and
13*9bb1b549SSpandan Das// limitations under the License.
14*9bb1b549SSpandan Das
15*9bb1b549SSpandan Daspackage cmd
16*9bb1b549SSpandan Das
17*9bb1b549SSpandan Dasimport (
18*9bb1b549SSpandan Das	"os"
19*9bb1b549SSpandan Das
20*9bb1b549SSpandan Das	"github.com/spf13/cobra"
21*9bb1b549SSpandan Das)
22*9bb1b549SSpandan Das
23*9bb1b549SSpandan Das// rootCmd represents the base command when called without any subcommands
24*9bb1b549SSpandan Dasvar rootCmd = &cobra.Command{
25*9bb1b549SSpandan Das	Use:   "go-code-tutorial",
26*9bb1b549SSpandan Das	Short: "A brief description of your application",
27*9bb1b549SSpandan Das	Long: `A longer description that spans multiple lines and likely contains
28*9bb1b549SSpandan Dasexamples and usage of using your application. For example:
29*9bb1b549SSpandan Das
30*9bb1b549SSpandan DasCobra is a CLI library for Go that empowers applications.
31*9bb1b549SSpandan DasThis application is a tool to generate the needed files
32*9bb1b549SSpandan Dasto quickly create a Cobra application.`,
33*9bb1b549SSpandan Das	// Uncomment the following line if your bare application
34*9bb1b549SSpandan Das	// has an action associated with it:
35*9bb1b549SSpandan Das	// Run: func(cmd *cobra.Command, args []string) { },
36*9bb1b549SSpandan Das}
37*9bb1b549SSpandan Das
38*9bb1b549SSpandan Das// Execute adds all child commands to the root command and sets flags appropriately.
39*9bb1b549SSpandan Das// This is called by main.main(). It only needs to happen once to the rootCmd.
40*9bb1b549SSpandan Dasfunc Execute() {
41*9bb1b549SSpandan Das	err := rootCmd.Execute()
42*9bb1b549SSpandan Das	if err != nil {
43*9bb1b549SSpandan Das		os.Exit(1)
44*9bb1b549SSpandan Das	}
45*9bb1b549SSpandan Das}
46*9bb1b549SSpandan Das
47*9bb1b549SSpandan Dasfunc init() {
48*9bb1b549SSpandan Das	rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
49*9bb1b549SSpandan Das}
50