main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 Xiaomi, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "fmt"
  17. "os"
  18. "github.com/open-falcon/falcon-plus/cmd"
  19. "github.com/spf13/cobra"
  20. )
  21. var versionFlag bool
  22. var RootCmd = &cobra.Command{
  23. Use: "open-falcon",
  24. RunE: func(c *cobra.Command, args []string) error {
  25. if versionFlag {
  26. fmt.Printf("%s version %s, build %s\n", BinaryName, Version, GitCommit)
  27. return nil
  28. }
  29. return c.Usage()
  30. },
  31. }
  32. func init() {
  33. RootCmd.AddCommand(cmd.Start)
  34. RootCmd.AddCommand(cmd.Stop)
  35. RootCmd.AddCommand(cmd.Restart)
  36. RootCmd.AddCommand(cmd.Check)
  37. RootCmd.AddCommand(cmd.Monitor)
  38. RootCmd.AddCommand(cmd.Reload)
  39. RootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "show version")
  40. cmd.Start.Flags().BoolVar(&cmd.PreqOrderFlag, "preq-order", false, "start modules in the order of prerequisites")
  41. cmd.Start.Flags().BoolVar(&cmd.ConsoleOutputFlag, "console-output", false, "print the module's output to the console")
  42. }
  43. func main() {
  44. if err := RootCmd.Execute(); err != nil {
  45. fmt.Println(err)
  46. os.Exit(1)
  47. }
  48. }