Simplify cli start command arguments
This commit is contained in:
parent
1373b3d71a
commit
2c23ee3ffb
5 changed files with 15 additions and 40 deletions
22
cli/setup.go
22
cli/setup.go
|
@ -19,7 +19,6 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/abcum/surreal/cnf"
|
||||
"github.com/abcum/surreal/log"
|
||||
|
@ -47,13 +46,6 @@ func setup() {
|
|||
opts.DB.Key = []byte(opts.DB.Code)
|
||||
}
|
||||
|
||||
if opts.DB.Time != "" {
|
||||
var err error
|
||||
if opts.DB.Sync, err = time.ParseDuration(opts.DB.Time); err != nil {
|
||||
log.Fatal("Specify a valid database sync time frequency")
|
||||
}
|
||||
}
|
||||
|
||||
switch len(opts.DB.Key) {
|
||||
case 0, 16, 24, 32:
|
||||
default:
|
||||
|
@ -168,20 +160,6 @@ func setup() {
|
|||
opts.Node.UUID = opts.Node.Name + "-" + uuid.NewV4().String()
|
||||
}
|
||||
|
||||
// Convert string args to slices
|
||||
for _, v := range strings.Split(opts.Node.Attr, ",") {
|
||||
if c := strings.Trim(v, " "); c != "" {
|
||||
opts.Node.Tags = append(opts.Node.Tags, c)
|
||||
}
|
||||
}
|
||||
|
||||
// Convert string args to slices
|
||||
for _, v := range strings.Split(opts.Cluster.Join, ",") {
|
||||
if c := strings.Trim(v, " "); c != "" {
|
||||
opts.Cluster.Peer = append(opts.Cluster.Peer, c)
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Ports
|
||||
// --------------------------------------------------
|
||||
|
|
|
@ -70,6 +70,7 @@ func init() {
|
|||
startCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master database authentication details.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.Auth.User, "auth-user", "", "The master username for the database. Use this as an alternative to the --auth flag.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.Auth.Pass, "auth-pass", "", "The master password for the database. Use this as an alternative to the --auth flag.")
|
||||
startCmd.PersistentFlags().StringSliceVar(&opts.Auth.Addr, "auth-addr", nil, "The IP address ranges from which master authentication is possible.")
|
||||
|
||||
startCmd.PersistentFlags().StringVar(&opts.Cert.Crt, "cert-crt", "", "Path to the server certificate. Needed when running in secure mode.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.Cert.Key, "cert-key", "", "Path to the server private key. Needed when running in secure mode.")
|
||||
|
@ -78,9 +79,9 @@ func init() {
|
|||
startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Crt, "db-crt", "", "Path to the certificate file used to connect to the remote database.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Key, "db-key", "", "Path to the private key file used to connect to the remote database.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.DB.Path, "db-path", "", flag("db"))
|
||||
startCmd.PersistentFlags().StringVar(&opts.DB.Time, "db-sync", "0s", "Something here")
|
||||
startCmd.PersistentFlags().DurationVar(&opts.DB.Time, "db-sync", 0, "Something here")
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.Cluster.Join, "join", "j", "", flag("join"))
|
||||
startCmd.PersistentFlags().StringSliceVarP(&opts.Node.Join, "join", "j", nil, flag("join"))
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key"))
|
||||
|
||||
|
|
10
cnf/cnf.go
10
cnf/cnf.go
|
@ -40,8 +40,7 @@ type Options struct {
|
|||
Host string // Surreal host to connect to
|
||||
Port string // Surreal port to connect to
|
||||
Base string // Base key to use in KV stores
|
||||
Time string // Timeframe for syncing data
|
||||
Sync time.Duration
|
||||
Time time.Duration // Timeframe for syncing data
|
||||
Cert struct {
|
||||
CA string
|
||||
Crt string
|
||||
|
@ -69,6 +68,7 @@ type Options struct {
|
|||
Auth string // Master authentication username:password
|
||||
User string // Master authentication username
|
||||
Pass string // Master authentication password
|
||||
Addr []string
|
||||
}
|
||||
|
||||
Node struct {
|
||||
|
@ -78,11 +78,7 @@ type Options struct {
|
|||
UUID string // UUID of this node
|
||||
Attr string // Comma separated tags for this node
|
||||
Tags []string // Slice of tags for this node
|
||||
}
|
||||
|
||||
Cluster struct {
|
||||
Join string // Comma separated peers to join
|
||||
Peer []string // Slice of peers to join
|
||||
Join []string // Slice of cluster peers to join
|
||||
}
|
||||
|
||||
Backups struct {
|
||||
|
|
|
@ -31,7 +31,7 @@ func init() {
|
|||
path := strings.TrimLeft(opts.DB.Path, "rixxdb://")
|
||||
|
||||
pntr, err = rixxdb.Open(path, &rixxdb.Config{
|
||||
SyncPolicy: opts.DB.Sync,
|
||||
SyncPolicy: opts.DB.Time,
|
||||
EncryptionKey: opts.DB.Key,
|
||||
})
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ func Setup(opts *cnf.Options) (err error) {
|
|||
cfg.MemberlistConfig.AdvertisePort = opts.Port.Tcp
|
||||
|
||||
srf, err = serf.Create(cfg)
|
||||
if len(opts.Cluster.Peer) > 0 {
|
||||
if _, err := srf.Join(opts.Cluster.Peer, true); err != nil {
|
||||
if len(opts.Node.Join) > 0 {
|
||||
if _, err := srf.Join(opts.Node.Join, true); err != nil {
|
||||
log.Infoln(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue