github.com/mutagen-io/mutagen@v0.18.0-rc1/cmd/mutagen/version.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/mutagen-io/mutagen/cmd"
     9  
    10  	"github.com/mutagen-io/mutagen/pkg/mutagen"
    11  )
    12  
    13  // versionMain is the entry point for the version command.
    14  func versionMain(_ *cobra.Command, _ []string) error {
    15  	// Print version information.
    16  	fmt.Println(mutagen.Version)
    17  
    18  	// Success.
    19  	return nil
    20  }
    21  
    22  // versionCommand is the version command.
    23  var versionCommand = &cobra.Command{
    24  	Use:          "version",
    25  	Short:        "Show version information",
    26  	Args:         cmd.DisallowArguments,
    27  	RunE:         versionMain,
    28  	SilenceUsage: true,
    29  }
    30  
    31  // versionConfiguration stores configuration for the version command.
    32  var versionConfiguration struct {
    33  	// help indicates whether or not to show help information and exit.
    34  	help bool
    35  }
    36  
    37  func init() {
    38  	// Grab a handle for the command line flags.
    39  	flags := versionCommand.Flags()
    40  
    41  	// Disable alphabetical sorting of flags in help output.
    42  	flags.SortFlags = false
    43  
    44  	// Manually add a help flag to override the default message. Cobra will
    45  	// still implement its logic automatically.
    46  	flags.BoolVarP(&versionConfiguration.help, "help", "h", false, "Show help information")
    47  }