github.com/mutagen-io/mutagen@v0.18.0-rc1/cmd/mutagen-agent/main.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/spf13/cobra" 7 8 "github.com/mutagen-io/mutagen/pkg/mutagen" 9 ) 10 11 // rootMain is the entry point for the root command. 12 func rootMain(command *cobra.Command, _ []string) error { 13 // If no commands were given, then print help information and bail. We don't 14 // have to worry about warning about arguments being present here (which 15 // would be incorrect usage) because arguments can't even reach this point 16 // (they will be mistaken for subcommands and a error will be displayed). 17 command.Help() 18 19 // Success. 20 return nil 21 } 22 23 // rootCommand is the root command. 24 var rootCommand = &cobra.Command{ 25 Use: "mutagen-agent", 26 Version: mutagen.Version, 27 Short: "The Mutagen agent should not be invoked by human beings", 28 RunE: rootMain, 29 SilenceUsage: true, 30 } 31 32 // rootConfiguration stores configuration for the root command. 33 var rootConfiguration struct { 34 // help indicates whether or not to show help information and exit. 35 help bool 36 } 37 38 func init() { 39 // Disable Cobra's command sorting behavior. By default, it sorts commands 40 // alphabetically in the help output. 41 cobra.EnableCommandSorting = false 42 43 // Disable Cobra's use of mousetrap. This is primarily for consistency with 44 // the main CLI, as it's not necessary for the agent. 45 cobra.MousetrapHelpText = "" 46 47 // Set the template used by the version flag. 48 rootCommand.SetVersionTemplate("Mutagen agent version {{ .Version }}\n") 49 50 // Grab a handle for the command line flags. 51 flags := rootCommand.Flags() 52 53 // Disable alphabetical sorting of flags in help output. 54 flags.SortFlags = false 55 56 // Manually add a help flag to override the default message. Cobra will 57 // still implement its logic automatically. 58 flags.BoolVarP(&rootConfiguration.help, "help", "h", false, "Show help information") 59 60 // Hide Cobra's completion command. 61 rootCommand.CompletionOptions.HiddenDefaultCmd = true 62 63 // Register commands. We do this here (rather than in individual init 64 // functions) so that we can control the order. 65 rootCommand.AddCommand( 66 installCommand, 67 synchronizerCommand, 68 forwarderCommand, 69 versionCommand, 70 legalCommand, 71 ) 72 } 73 74 func main() { 75 // Execute the root command. 76 if err := rootCommand.Execute(); err != nil { 77 os.Exit(1) 78 } 79 }