Simplify cli start command arguments

This commit is contained in:
Tobie Morgan Hitchcock 2017-02-20 16:16:19 +00:00
parent 1373b3d71a
commit 2c23ee3ffb
5 changed files with 15 additions and 40 deletions

View file

@ -19,7 +19,6 @@ import (
"os" "os"
"regexp" "regexp"
"strings" "strings"
"time"
"github.com/abcum/surreal/cnf" "github.com/abcum/surreal/cnf"
"github.com/abcum/surreal/log" "github.com/abcum/surreal/log"
@ -47,13 +46,6 @@ func setup() {
opts.DB.Key = []byte(opts.DB.Code) 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) { switch len(opts.DB.Key) {
case 0, 16, 24, 32: case 0, 16, 24, 32:
default: default:
@ -168,20 +160,6 @@ func setup() {
opts.Node.UUID = opts.Node.Name + "-" + uuid.NewV4().String() 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 // Ports
// -------------------------------------------------- // --------------------------------------------------

View file

@ -70,6 +70,7 @@ func init() {
startCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master database authentication details.") 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.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().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.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.") 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.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.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.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")) startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key"))

View file

@ -34,14 +34,13 @@ type Auth struct {
// Options defines global configuration options // Options defines global configuration options
type Options struct { type Options struct {
DB struct { DB struct {
Key []byte // Data encryption key Key []byte // Data encryption key
Code string // Data encruption key string Code string // Data encruption key string
Path string // Path to store the data file Path string // Path to store the data file
Host string // Surreal host to connect to Host string // Surreal host to connect to
Port string // Surreal port to connect to Port string // Surreal port to connect to
Base string // Base key to use in KV stores Base string // Base key to use in KV stores
Time string // Timeframe for syncing data Time time.Duration // Timeframe for syncing data
Sync time.Duration
Cert struct { Cert struct {
CA string CA string
Crt string Crt string
@ -69,6 +68,7 @@ type Options struct {
Auth string // Master authentication username:password Auth string // Master authentication username:password
User string // Master authentication username User string // Master authentication username
Pass string // Master authentication password Pass string // Master authentication password
Addr []string
} }
Node struct { Node struct {
@ -78,11 +78,7 @@ type Options struct {
UUID string // UUID of this node UUID string // UUID of this node
Attr string // Comma separated tags for this node Attr string // Comma separated tags for this node
Tags []string // Slice of tags for this node Tags []string // Slice of tags for this node
} Join []string // Slice of cluster peers to join
Cluster struct {
Join string // Comma separated peers to join
Peer []string // Slice of peers to join
} }
Backups struct { Backups struct {

View file

@ -31,7 +31,7 @@ func init() {
path := strings.TrimLeft(opts.DB.Path, "rixxdb://") path := strings.TrimLeft(opts.DB.Path, "rixxdb://")
pntr, err = rixxdb.Open(path, &rixxdb.Config{ pntr, err = rixxdb.Open(path, &rixxdb.Config{
SyncPolicy: opts.DB.Sync, SyncPolicy: opts.DB.Time,
EncryptionKey: opts.DB.Key, EncryptionKey: opts.DB.Key,
}) })

View file

@ -48,8 +48,8 @@ func Setup(opts *cnf.Options) (err error) {
cfg.MemberlistConfig.AdvertisePort = opts.Port.Tcp cfg.MemberlistConfig.AdvertisePort = opts.Port.Tcp
srf, err = serf.Create(cfg) srf, err = serf.Create(cfg)
if len(opts.Cluster.Peer) > 0 { if len(opts.Node.Join) > 0 {
if _, err := srf.Join(opts.Cluster.Peer, true); err != nil { if _, err := srf.Join(opts.Node.Join, true); err != nil {
log.Infoln(err) log.Infoln(err)
} }
} }