github.com/exercism/v2-configlet@v3.9.2+incompatible/cmd/root.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	"github.com/exercism/cli/cli"
     9  	"github.com/exercism/configlet/ui"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  // Version is the current version of the tool.
    14  const Version = "3.9.2"
    15  
    16  var (
    17  	// binaryName is this tool's given name. While we have named it configlet, others
    18  	// may choose to rename it. This var enables the use of it's name, whatever it is,
    19  	// in any help/usage text.
    20  	binaryName = os.Args[0]
    21  	//configletCLI is an updatable CLI binary.
    22  	configletCLI *cli.CLI
    23  	// pathExample is an illustration of the path argument necessary for some commands.
    24  	pathExample = "<path/to/track>"
    25  )
    26  
    27  // RootCmd represents the base command when called without any subcommands
    28  var RootCmd = &cobra.Command{
    29  	Use:     binaryName,
    30  	Short:   "A tool for managing Exercism language track repositories.",
    31  	Long:    binaryName + " version " + Version + "\n\n" + "A tool for managing Exercism language track repositories.",
    32  	Example: rootExampleText(),
    33  }
    34  
    35  func rootExampleText() string {
    36  	cmds := []string{
    37  		"%[1]s fmt %[2]s",
    38  		"%[1]s generate %[2]s",
    39  		"%[1]s lint %[2]s",
    40  	}
    41  	s := "  " + strings.Join(cmds, "\n\n  ")
    42  	return fmt.Sprintf(s, binaryName, pathExample)
    43  }
    44  
    45  // Execute adds all child commands to the root command & sets flags appropriately.
    46  // This is called by main.main(). It only needs to happen once to the rootCmd.
    47  func Execute() {
    48  	if err := RootCmd.Execute(); err != nil {
    49  		ui.PrintError(err.Error())
    50  		os.Exit(-1)
    51  	}
    52  }
    53  
    54  func init() {
    55  	cli.ReleaseURL = "https://api.github.com/repos/exercism/configlet/releases"
    56  	configletCLI = cli.New(Version)
    57  }