From fbaba15776ad20f0831a88430ab42cc1f02764bc Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 24 Jan 2025 10:15:37 +0000 Subject: [PATCH] Adapt override to non-pointer values --- cmd/africastalking/main.go | 14 ++++---------- cmd/async/main.go | 14 ++++---------- cmd/http/main.go | 14 ++++---------- cmd/main.go | 8 ++++---- cmd/ssh/main.go | 9 +++++---- config/args.go | 20 -------------------- devtools/admin/main.go | 14 ++++---------- devtools/store/dump/main.go | 14 ++++---------- go.mod | 4 ++-- go.sum | 8 ++++---- testutil/fsdb.go | 4 ++-- testutil/gdbmdb.go | 4 ++-- 12 files changed, 39 insertions(+), 88 deletions(-) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 1d24358..2975d03 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -44,14 +44,12 @@ func main() { var err error var gettextDir string var langs args.LangVar - var resourceDir string flag.BoolVar(&engineDebug, "d", false, "use engine debug output") - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(&resourceDir, "resource-dir", "", "resource data directory. If set, overrides --resource to create a non-binary fsdb for the given path.") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&host, "h", config.Host(), "http host") flag.UintVar(&port, "p", config.Port(), "http port") @@ -59,10 +57,6 @@ func main() { flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() - if resourceDir != "" { - *override.ResourceConn = resourceDir - override.ResourceConnMode = storage.DBMODE_TEXT - } config.Apply(override) conns, err := config.GetConns() if err != nil { diff --git a/cmd/async/main.go b/cmd/async/main.go index 9feac12..a55a19b 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -53,14 +53,12 @@ func main() { var err error var gettextDir string var langs args.LangVar - var resourceDir string flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(&resourceDir, "resource-dir", "", "resource data directory. If set, overrides --resource to create a non-binary fsdb for the given path.") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") @@ -70,10 +68,6 @@ func main() { flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() - if resourceDir != "" { - *override.ResourceConn = resourceDir - override.ResourceConnMode = storage.DBMODE_TEXT - } config.Apply(override) conns, err := config.GetConns() if err != nil { diff --git a/cmd/http/main.go b/cmd/http/main.go index ec4b95b..e691254 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -43,13 +43,11 @@ func main() { var err error var gettextDir string var langs args.LangVar - var resourceDir string - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(&resourceDir, "resource-dir", "", "resource data directory. If set, overrides --resource to create a non-binary fsdb for the given path.") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") @@ -59,10 +57,6 @@ func main() { flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() - if resourceDir != "" { - *override.ResourceConn = resourceDir - override.ResourceConnMode = storage.DBMODE_TEXT - } config.Apply(override) conns, err := config.GetConns() if err != nil { diff --git a/cmd/main.go b/cmd/main.go index 7f83863..360f8af 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -38,10 +38,10 @@ func main() { var langs args.LangVar flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory") diff --git a/cmd/ssh/main.go b/cmd/ssh/main.go index 86bcf4b..d3afbb0 100644 --- a/cmd/ssh/main.go +++ b/cmd/ssh/main.go @@ -38,10 +38,11 @@ func main() { var stateDebug bool var host string var port uint - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.ResourceConn, "resource", "?", "resource connection string") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource connection string") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&host, "h", config.HostSSH(), "socket host") diff --git a/config/args.go b/config/args.go index 67e0528..20f80bf 100644 --- a/config/args.go +++ b/config/args.go @@ -6,35 +6,15 @@ import ( ) func NewOverride() *viseconfig.Override { - var a string - var b string - var c string - var d string o := &viseconfig.Override{ - DbConn: &a, - StateConn: &b, StateConnMode: storage.DBMODE_TEXT, - ResourceConn: &c, ResourceConnMode: storage.DBMODE_TEXT, - UserConn: &d, UserConnMode: storage.DBMODE_BINARY, } return o } func Apply(o *viseconfig.Override) error { - if *o.DbConn == "?" { - o.DbConn = nil - } - if *o.ResourceConn == "?" { - o.ResourceConn = nil - } - if *o.UserConn == "?" { - o.UserConn = nil - } - if *o.StateConn == "?" { - o.StateConn = nil - } viseconfig.ApplyConn(o) return nil } diff --git a/devtools/admin/main.go b/devtools/admin/main.go index 4e93ce8..3ae40b6 100644 --- a/devtools/admin/main.go +++ b/devtools/admin/main.go @@ -25,21 +25,15 @@ func main() { override := config.NewOverride() var sessionId string - var resourceDir string flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(&resourceDir, "resource-dir", "", "resource data directory. If set, overrides --resource to create a non-binary fsdb for the given path.") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.Parse() - if resourceDir != "" { - *override.ResourceConn = resourceDir - override.ResourceConnMode = storage.DBMODE_TEXT - } config.Apply(override) conns, err := config.GetConns() if err != nil { diff --git a/devtools/store/dump/main.go b/devtools/store/dump/main.go index f58efce..6844a22 100644 --- a/devtools/store/dump/main.go +++ b/devtools/store/dump/main.go @@ -38,21 +38,15 @@ func main() { var engineDebug bool var err error var first bool - var resourceDir string flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") - flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") - flag.StringVar(override.ResourceConn, "resource", "?", "resource data directory") - flag.StringVar(&resourceDir, "resource-dir", "", "resource data directory. If set, overrides --resource to create a non-binary fsdb for the given path.") - flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string") - flag.StringVar(override.StateConn, "state", "?", "state store connection string") + flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)") + flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory") + flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string") + flag.StringVar(&override.StateConn, "state", "?", "state store connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.Parse() - if resourceDir != "" { - *override.ResourceConn = resourceDir - override.ResourceConnMode = storage.DBMODE_TEXT - } config.Apply(override) conns, err := config.GetConns() if err != nil { diff --git a/go.mod b/go.mod index 4fb3c50..4171c44 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250121135150-e0b539809805 - git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2 + git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1 + git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84 github.com/alecthomas/assert/v2 v2.2.2 github.com/gofrs/uuid v4.4.0+incompatible diff --git a/go.sum b/go.sum index f3aa2bb..c4ef475 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,10 @@ git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 h1:sPcqXQcywxA8W git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ= git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= -git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250121135150-e0b539809805 h1:deGnqf4YCsbxhXgjFEjYjTUCvciLEmI26T9IysRsQXY= -git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250121135150-e0b539809805/go.mod h1:9bc3d//Qqm11hz7GYRdQc1Uan+0GJIOpvRBbv8cHMu8= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2 h1:ON77G5K0JNuwPb5JT/hRfF6G6+xstlBQgEIEzWydnhg= -git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1 h1:BJHfokTHzrw9QjQ+4s2HmSER0iBPuE7byW5oQC2zLIQ= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa h1:yQLKwby3eD/zNjNw/INU5lGiLuWPEHdsgASwMA4UptE= +git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84 h1:VoBmqsjlRdz+IPbtKsAkc1IrMepjR+QlesZT31Jokrk= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84/go.mod h1:DpibtYpnT3nG4Kn556hRAkdu4+CtiI/6MbnQHal51mQ= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= diff --git a/testutil/fsdb.go b/testutil/fsdb.go index 7482bd0..9c7045c 100644 --- a/testutil/fsdb.go +++ b/testutil/fsdb.go @@ -16,10 +16,10 @@ func init() { if err != nil { panic(err) } - override.StateConn = &stateDir + override.StateConn = stateDir userDir, err := os.MkdirTemp("", "sarafu-vise-menutraversal-fs-user-") if err != nil { panic(err) } - override.UserConn = &userDir + override.UserConn = userDir } diff --git a/testutil/gdbmdb.go b/testutil/gdbmdb.go index 09e7dd5..158c187 100644 --- a/testutil/gdbmdb.go +++ b/testutil/gdbmdb.go @@ -21,7 +21,7 @@ func init() { if err != nil { panic(err) } - override.StateConn = &stateDir + override.StateConn = stateDir userDir, err := os.MkdirTemp("", "sarafu-vise-menutraversal-gdbm-user-") if err != nil { panic(err) @@ -30,5 +30,5 @@ func init() { if err != nil { panic(err) } - override.UserConn = &userDir + override.UserConn = userDir }