From 828cd4e82844fca060900b8477f122425fdda36d Mon Sep 17 00:00:00 2001 From: kai Date: Thu, 18 Mar 2021 16:21:42 +0000 Subject: [PATCH] All boolean properties in options files should be of type bool, rather than truthy strings. Remove unused argument `background` #313 --- cmd/service.go | 1 - constants/args.go | 1 - constants/defaultoptions.go | 13 ++++++++----- steampipeconfig/options/connection.go | 16 ++-------------- steampipeconfig/options/database.go | 3 --- steampipeconfig/options/general.go | 3 --- steampipeconfig/options/options.go | 3 --- steampipeconfig/options/terminal.go | 20 +++----------------- steampipeconfig/parser.go | 2 -- 9 files changed, 13 insertions(+), 49 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 35f0c4e4a..2f41ab097 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -52,7 +52,6 @@ connection from any Postgres compatible database client.`, cmdconfig. OnCmd(cmd). - AddBoolFlag(constants.ArgBackground, "", true, "Run service in the background"). // for now default port to -1 so we fall back to the default of the deprecated arg AddIntFlag(constants.ArgPort, "", constants.DatabaseDefaultPort, "Database service port."). AddIntFlag(constants.ArgPortDeprecated, "", constants.DatabaseDefaultPort, "Database service port.", cmdconfig.FlagOptions.Deprecated(constants.ArgPort)). diff --git a/constants/args.go b/constants/args.go index e636c5668..ae9f2b98a 100644 --- a/constants/args.go +++ b/constants/args.go @@ -12,7 +12,6 @@ const ( ArgTimer = "timing" ArgOn = "on" ArgOff = "off" - ArgBackground = "background" ArgPortDeprecated = "db-port" ArgPort = "database-port" ArgListenAddressDeprecated = "listen" diff --git a/constants/defaultoptions.go b/constants/defaultoptions.go index 9326bf467..f44261d57 100644 --- a/constants/defaultoptions.go +++ b/constants/defaultoptions.go @@ -2,22 +2,25 @@ package constants const DefaultSPCContent = ` # options "connection" { -# cache = "on" # on, off +# cache = true # true, false # cache_ttl = 300 # int = time in seconds # } + # options "database" { # port = 9193 # listen = "local" # } + # options "terminal" { -# header = "off" # on, off -# multi = "off" # on, off +# multi = false # true, false # output = "table" # json, csv, table, line +# header = false # true, false # separator = "," # any single char -# timing = "off" # on, off +# timing = false # true, false # } + # options "general" { -# update_check = "on" # on, off +# update_check = true # true, false # } ` diff --git a/steampipeconfig/options/connection.go b/steampipeconfig/options/connection.go index 719b18c45..4fa964a0c 100644 --- a/steampipeconfig/options/connection.go +++ b/steampipeconfig/options/connection.go @@ -1,21 +1,9 @@ package options -import "github.com/turbot/go-kit/types" - // options.Connection type Connection struct { - // string containing a bool - supports true/false/off/on etc - CacheBoolString *string `hcl:"cache"` - CacheTTL *int `hcl:"cache_ttl"` - - // fields which we populate by converting the parsed values - Cache *bool -} - -// Populate :: convert strings representing bool values into bool pointers -func (c *Connection) Populate() { - // convert CacheBoolString to a bool ptr - c.Cache = types.ToBoolPtr(c.CacheBoolString) + Cache *bool `hcl:"cache"` + CacheTTL *int `hcl:"cache_ttl"` } func (c *Connection) ConfigMap() map[string]interface{} { diff --git a/steampipeconfig/options/database.go b/steampipeconfig/options/database.go index b60119585..ca00f0849 100644 --- a/steampipeconfig/options/database.go +++ b/steampipeconfig/options/database.go @@ -8,9 +8,6 @@ type Database struct { Listen *string `hcl:"listen"` } -// Populate :: nothing to do -func (d Database) Populate() {} - // ConfigMap :: create a config map to pass to viper func (c *Database) ConfigMap() map[string]interface{} { // only add keys which are non null diff --git a/steampipeconfig/options/general.go b/steampipeconfig/options/general.go index ce96bf6d4..3c9f0cff0 100644 --- a/steampipeconfig/options/general.go +++ b/steampipeconfig/options/general.go @@ -8,9 +8,6 @@ type General struct { UpdateCheck *string `hcl:"update_check"` } -// Populate :: nothing to do -func (d General) Populate() {} - // ConfigMap :: create a config map to pass to viper func (c General) ConfigMap() map[string]interface{} { // only add keys which are non null diff --git a/steampipeconfig/options/options.go b/steampipeconfig/options/options.go index c7880bf1a..142a2a24d 100644 --- a/steampipeconfig/options/options.go +++ b/steampipeconfig/options/options.go @@ -9,9 +9,6 @@ const ( ) type Options interface { - // once we have parsed the hcl, we may need to convert the parsed values - // - for example we accept true/false/on/off for bool values - convert these to bool - Populate() // map of config keys to values - used to populate viper ConfigMap() map[string]interface{} } diff --git a/steampipeconfig/options/terminal.go b/steampipeconfig/options/terminal.go index d5a6385b4..1d57a0ff7 100644 --- a/steampipeconfig/options/terminal.go +++ b/steampipeconfig/options/terminal.go @@ -1,7 +1,6 @@ package options import ( - "github.com/turbot/go-kit/types" "github.com/turbot/steampipe/constants" ) @@ -9,22 +8,9 @@ import ( type Terminal struct { Output *string `hcl:"output"` Separator *string `hcl:"separator"` - // strings containing a bool - supports true/false/off/on etc - HeaderBoolString *string `hcl:"header"` - MultiBoolString *string `hcl:"multi"` - TimingBoolString *string `hcl:"timing"` - - // fields which we populate by converting the parsed values - Header *bool - Multi *bool - Timing *bool -} - -// Populate :: convert strings representing bool values into bool pointers -func (c *Terminal) Populate() { - c.Header = types.ToBoolPtr(c.HeaderBoolString) - c.Multi = types.ToBoolPtr(c.MultiBoolString) - c.Timing = types.ToBoolPtr(c.TimingBoolString) + Header *bool `hcl:"header"` + Multi *bool `hcl:"multi"` + Timing *bool `hcl:"timing"` } // ConfigMap :: create a config map to pass to viper diff --git a/steampipeconfig/parser.go b/steampipeconfig/parser.go index 4f5dc5c1f..8791981c1 100644 --- a/steampipeconfig/parser.go +++ b/steampipeconfig/parser.go @@ -129,8 +129,6 @@ func parseOptions(block *hcl.Block) (options.Options, hcl.Diagnostics) { return nil, diags } - // now call the options.Populate to convert bool string fields into actual bools - dest.Populate() return dest, nil }