github.com/mutagen-io/mutagen@v0.18.0-rc1/cmd/mutagen/daemon/main.go (about) 1 package daemon 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/mutagen-io/mutagen/pkg/daemon" 7 ) 8 9 // daemonMain is the entry point for the daemon command. 10 func daemonMain(command *cobra.Command, _ []string) error { 11 // If no commands were given, then print help information and bail. We don't 12 // have to worry about warning about arguments being present here (which 13 // would be incorrect usage) because arguments can't even reach this point 14 // (they will be mistaken for subcommands and a error will be displayed). 15 command.Help() 16 17 // Success. 18 return nil 19 } 20 21 // DaemonCommand is the daemon command. 22 var DaemonCommand = &cobra.Command{ 23 Use: "daemon", 24 Short: "Control the lifecycle of the Mutagen daemon", 25 RunE: daemonMain, 26 SilenceUsage: true, 27 } 28 29 // daemonConfiguration stores configuration for the daemon command. 30 var daemonConfiguration struct { 31 // help indicates whether or not to show help information and exit. 32 help bool 33 } 34 35 func init() { 36 // Grab a handle for the command line flags. 37 flags := DaemonCommand.Flags() 38 39 // Disable alphabetical sorting of flags in help output. 40 flags.SortFlags = false 41 42 // Manually add a help flag to override the default message. Cobra will 43 // still implement its logic automatically. 44 flags.BoolVarP(&daemonConfiguration.help, "help", "h", false, "Show help information") 45 46 // Compute supported commands. We have to do this in advance since 47 // AddCommand can't be invoked twice. 48 supportedCommands := []*cobra.Command{ 49 runCommand, 50 startCommand, 51 stopCommand, 52 } 53 if daemon.RegistrationSupported { 54 supportedCommands = append(supportedCommands, 55 registerCommand, 56 unregisterCommand, 57 ) 58 } 59 60 // Register commands. 61 DaemonCommand.AddCommand(supportedCommands...) 62 }