github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/controller/plugin/manager/cmd/serve.go (about) 1 // Copyright © 2016 NAME HERE <EMAIL ADDRESS> 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 15 package cmd 16 17 import ( 18 "fmt" 19 20 "github.com/spf13/cobra" 21 ) 22 23 var ( 24 Host string 25 Port string 26 27 DBHost string 28 DBPort string 29 DBUser string 30 DBName string 31 DBPasswd string 32 33 DockerHost string 34 35 AllowedDomain string 36 ) 37 38 // serveCmd represents the serve command 39 var serveCmd = &cobra.Command{ 40 Use: "serve", 41 Short: "start the manager server", 42 Long: `start the manager server`, 43 Run: func(cmd *cobra.Command, args []string) { 44 // TODO: Work your own magic here 45 fmt.Printf("database info host=%s port=%s user=%s name=%s passwd=%s\n", 46 DBHost, DBPort, DBUser, DBName, DBPasswd) 47 //initDB(DBHost, DBPort, DBUser, DBName, DBPasswd) 48 49 fmt.Println("serve called", Host, Port) 50 runServer(Host, Port) 51 }, 52 } 53 54 func init() { 55 RootCmd.AddCommand(serveCmd) 56 57 // Here you will define your flags and configuration settings. 58 59 // Cobra supports Persistent Flags which will work for this command 60 // and all subcommands, e.g.: 61 // serveCmd.PersistentFlags().String("foo", "", "A help for foo") 62 63 // Cobra supports local flags which will only run when this command 64 // is called directly, e.g.: 65 // serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 66 67 serveCmd.Flags().StringVarP(&Host, "host", "H", "localhost", "the ip address of manager server") 68 serveCmd.Flags().StringVarP(&Port, "port", "p", ":8081", "the port of manager server") 69 70 serveCmd.Flags().StringVarP(&DBHost, "db-host", "d", "localhost", "the address of database server") 71 serveCmd.Flags().StringVarP(&DBPort, "db-port", "P", "5432", "the port of database server, default pgsql port is 5432") 72 serveCmd.Flags().StringVarP(&DBUser, "db-user", "u", "shipyard", "the user of database server") 73 serveCmd.Flags().StringVarP(&DBName, "db-name", "n", "shipyard", "the database name of database server") 74 serveCmd.Flags().StringVarP(&DBPasswd, "db-passwd", "w", "111111", "the database passwd") 75 76 serveCmd.Flags().StringVarP(&DockerHost, "docker-host", "s", "http://192.168.96.99:4000", "the docker host") 77 78 serveCmd.Flags().StringVarP(&AllowedDomain, "allowed-domain", "o", "http://192.168.86.170:8888", "manager allowed origin") 79 }