surrealpatch/cli/cli.go

71 lines
2.1 KiB
Go
Raw Normal View History

2016-02-26 17:25:32 +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 (
"log"
"os"
"github.com/spf13/cobra"
2016-02-28 22:26:19 +00:00
"github.com/abcum/surreal/cnf"
2016-03-14 16:35:10 +00:00
"github.com/abcum/surreal/db"
2016-02-26 17:25:32 +00:00
"github.com/abcum/surreal/server"
)
var opts *cnf.Options
2016-02-28 22:26:19 +00:00
2016-02-26 17:25:32 +00:00
var mainCmd = &cobra.Command{
2016-02-26 18:53:35 +00:00
Use: "surreal",
Short: "SurrealDB command-line interface and server",
2016-02-26 17:25:32 +00:00
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
2016-03-14 16:35:10 +00:00
return db.Setup(opts)
2016-02-26 17:25:32 +00:00
},
RunE: func(cmd *cobra.Command, args []string) error {
2016-02-28 22:26:19 +00:00
return server.Setup(opts)
2016-02-26 17:25:32 +00:00
},
}
func init() {
mainCmd.AddCommand(
sqlCmd,
importCmd,
exportCmd,
versionCmd,
)
opts = &cnf.Options{}
2016-02-28 22:26:19 +00:00
mainCmd.PersistentFlags().StringVarP(&opts.Auth, "auth", "a", "", "Set master authentication details using user:pass format")
2016-03-14 16:35:10 +00:00
mainCmd.PersistentFlags().StringVarP(&opts.Db, "db", "d", "rpc://node@127.0.0.1:26257", "Set backend datastore")
2016-02-28 22:26:19 +00:00
mainCmd.PersistentFlags().StringVarP(&opts.Port, "port", "", ":8000", "The host:port on which to serve the web interface")
mainCmd.PersistentFlags().StringVarP(&opts.Http, "port-http", "", ":33693", "The host:port on which to serve the http sql server")
mainCmd.PersistentFlags().StringVarP(&opts.Sock, "port-sock", "", ":33793", "The host:port on which to serve the sock sql server")
mainCmd.PersistentFlags().StringVarP(&opts.Base, "base", "b", "surreal", "Name of the root database key")
mainCmd.PersistentFlags().BoolVarP(&opts.Verbose, "verbose", "v", false, "Enable verbose output")
2016-02-26 17:25:32 +00:00
cobra.OnInitialize(setup)
2016-02-26 17:25:32 +00:00
}
// Run runs the cli app
func Run() {
if err := mainCmd.Execute(); err != nil {
log.Println(err)
os.Exit(-1)
}
}