github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/cmd/tools/common.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package tools contains the CLI commands for Jackal.
     5  package tools
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/Racer159/jackal/src/cmd/common"
    11  	"github.com/Racer159/jackal/src/config"
    12  	"github.com/Racer159/jackal/src/config/lang"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  var toolsCmd = &cobra.Command{
    17  	Use:     "tools",
    18  	Aliases: []string{"t"},
    19  	PersistentPreRun: func(cmd *cobra.Command, _ []string) {
    20  		config.SkipLogFile = true
    21  
    22  		// Skip for vendor-only commands
    23  		if common.CheckVendorOnlyFromPath(cmd) {
    24  			return
    25  		}
    26  
    27  		common.SetupCLI()
    28  	},
    29  	Short: lang.CmdToolsShort,
    30  }
    31  
    32  // Include adds the tools command to the root command.
    33  func Include(rootCmd *cobra.Command) {
    34  	rootCmd.AddCommand(toolsCmd)
    35  }
    36  
    37  // newVersionCmd is a generic version command for tools
    38  func newVersionCmd(name, version string) *cobra.Command {
    39  	return &cobra.Command{
    40  		Use:   "version",
    41  		Args:  cobra.NoArgs,
    42  		Short: lang.CmdToolsVersionShort,
    43  		Run: func(cmd *cobra.Command, _ []string) {
    44  			cmd.Println(fmt.Sprintf("%s %s", name, version))
    45  		},
    46  	}
    47  }