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

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"os/signal"
     6  
     7  	"github.com/spf13/cobra"
     8  
     9  	"github.com/mutagen-io/mutagen/cmd"
    10  
    11  	"github.com/mutagen-io/mutagen/pkg/mutagen"
    12  )
    13  
    14  // rootMain is the entry point for the root command.
    15  func rootMain(_ *cobra.Command, _ []string) error {
    16  	// Set up signal handling.
    17  	signalTermination := make(chan os.Signal, 1)
    18  	signal.Notify(signalTermination, cmd.TerminationSignals...)
    19  
    20  	// Wait for termination.
    21  	<-signalTermination
    22  
    23  	// Success.
    24  	return nil
    25  }
    26  
    27  // rootCommand is the root command.
    28  var rootCommand = &cobra.Command{
    29  	Use:          "mutagen-sidecar",
    30  	Version:      mutagen.Version,
    31  	Short:        "Entry point for sidecar containers hosting Mutagen sessions",
    32  	RunE:         rootMain,
    33  	SilenceUsage: true,
    34  }
    35  
    36  // rootConfiguration stores configuration for the root command.
    37  var rootConfiguration struct {
    38  	// help indicates whether or not to show help information and exit.
    39  	help bool
    40  }
    41  
    42  func init() {
    43  	// Disable Cobra's command sorting behavior. By default, it sorts commands
    44  	// alphabetically in the help output.
    45  	cobra.EnableCommandSorting = false
    46  
    47  	// Disable Cobra's use of mousetrap. This is primarily for consistency with
    48  	// the main CLI, as it's not necessary for the sidecar.
    49  	cobra.MousetrapHelpText = ""
    50  
    51  	// Set the template used by the version flag.
    52  	rootCommand.SetVersionTemplate("Mutagen sidecar version {{ .Version }}\n")
    53  
    54  	// Grab a handle for the command line flags.
    55  	flags := rootCommand.Flags()
    56  
    57  	// Disable alphabetical sorting of flags in help output.
    58  	flags.SortFlags = false
    59  
    60  	// Manually add a help flag to override the default message. Cobra will
    61  	// still implement its logic automatically.
    62  	flags.BoolVarP(&rootConfiguration.help, "help", "h", false, "Show help information")
    63  
    64  	// Hide Cobra's completion command.
    65  	rootCommand.CompletionOptions.HiddenDefaultCmd = true
    66  
    67  	// Register commands. We do this here (rather than in individual init
    68  	// functions) so that we can control the order.
    69  	rootCommand.AddCommand(
    70  		versionCommand,
    71  		legalCommand,
    72  	)
    73  }
    74  
    75  func main() {
    76  	// Execute the root command.
    77  	if err := rootCommand.Execute(); err != nil {
    78  		os.Exit(1)
    79  	}
    80  }