surrealpatch/cli/start.go

88 lines
2.5 KiB
Go
Raw Normal View History

2016-04-08 19:29:13 +00:00
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/abcum/surreal/db"
2016-07-04 10:33:07 +00:00
"github.com/abcum/surreal/tcp"
2016-04-08 19:29:13 +00:00
"github.com/abcum/surreal/web"
)
var startCmd = &cobra.Command{
Use: "start",
Short: "Start the database and http server",
2016-07-04 10:33:07 +00:00
PreRun: func(cmd *cobra.Command, args []string) {
2016-04-08 19:29:13 +00:00
fmt.Print(logo)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
2016-07-04 10:33:07 +00:00
if err = db.Setup(opts); err != nil {
2016-04-08 19:29:13 +00:00
return
}
2016-07-04 10:33:07 +00:00
if err = tcp.Setup(opts); err != nil {
2016-04-08 19:29:13 +00:00
return
}
2016-07-04 10:33:07 +00:00
if err = web.Setup(opts); err != nil {
2016-04-08 19:29:13 +00:00
return
}
return
},
PostRun: func(cmd *cobra.Command, args []string) {
2016-07-04 10:33:07 +00:00
tcp.Exit()
2016-04-08 19:29:13 +00:00
web.Exit()
2016-07-04 10:33:07 +00:00
db.Exit()
2016-04-08 19:29:13 +00:00
},
}
func init() {
startCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "", flag("auth"))
startCmd.PersistentFlags().StringVar(&opts.Auth.User, "auth-user", "", flag("auth-user"))
startCmd.PersistentFlags().StringVar(&opts.Auth.Pass, "auth-pass", "", flag("auth-pass"))
2016-07-04 10:33:07 +00:00
startCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "key", "k", "", flag("key"))
2016-04-08 19:29:13 +00:00
2016-07-04 10:33:07 +00:00
startCmd.PersistentFlags().StringVar(&opts.Cert.Crt, "cert-crt", "", flag("cert-crt"))
startCmd.PersistentFlags().StringVar(&opts.Cert.Key, "cert-key", "", flag("cert-key"))
startCmd.PersistentFlags().StringVar(&opts.Cert.Pem, "cert-pem", "", flag("cert-pem"))
2016-04-08 19:29:13 +00:00
2016-07-04 10:33:07 +00:00
startCmd.PersistentFlags().StringVar(&opts.DB.Base, "db-base", "", flag("db-base"))
startCmd.PersistentFlags().StringVar(&opts.DB.Path, "db-path", "", flag("db-path"))
startCmd.PersistentFlags().IntVar(&opts.Port.Tcp, "port-tcp", 0, flag("port-tcp"))
startCmd.PersistentFlags().IntVar(&opts.Port.Web, "port-web", 0, flag("port-web"))
2016-04-08 19:29:13 +00:00
startCmd.PersistentFlags().StringVarP(&opts.Node.Name, "name", "n", "", flag("name"))
startCmd.PersistentFlags().StringVarP(&opts.Node.Attr, "tags", "t", "", flag("tags"))
startCmd.PersistentFlags().StringVarP(&opts.Cluster.Join, "join", "j", "", flag("join"))
startCmd.PersistentFlags().MarkHidden("auth-user")
startCmd.PersistentFlags().MarkHidden("auth-pass")
}