Skip to content

Commit

Permalink
[cli] use resty_env.value instead of .get
Browse files Browse the repository at this point in the history
* .value returns nil when the value is empty string
* so it can be chain with `or` for a default value
  • Loading branch information
mikz committed Nov 28, 2017
1 parent 2981d47 commit 40dfaaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions gateway/src/apicast/cli/command/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end


local function apicast_root()
return resty_env.get('APICAST_DIR') or pl.path.abspath('.')
return resty_env.value('APICAST_DIR') or pl.path.abspath('.')
end

local function nginx_config(context,path)
Expand Down Expand Up @@ -167,31 +167,31 @@ local function configure(cmd)
cmd:option("--template", "Nginx config template.", 'conf/nginx.conf.liquid')


cmd:option('-e --environment', "Deployment to start. Can also be a path to a Lua file.", resty_env.get('THREESCALE_DEPLOYMENT_ENV') or 'production'):count('*')
cmd:option('-e --environment', "Deployment to start. Can also be a path to a Lua file.", resty_env.value('THREESCALE_DEPLOYMENT_ENV') or 'production'):count('*')
cmd:flag('--dev', 'Start in development environment')

cmd:flag("-m --master", "Test the nginx config"):args('?')
cmd:flag("-t --test", "Test the nginx config")
cmd:flag("--debug", "Debug mode. Prints more information.")
cmd:option("-c --configuration",
"Path to custom config file (JSON)",
resty_env.get('APICAST_CONFIGURATION'))
resty_env.value('APICAST_CONFIGURATION'))
cmd:flag("-d --daemon", "Daemonize.")
cmd:option("-w --workers",
"Number of worker processes to start.",
resty_env.get('APICAST_WORKERS') or 1)
resty_env.value('APICAST_WORKERS') or 1)
cmd:option("-p --pid", "Path to the PID file.")
cmd:mutex(
cmd:flag('-b --boot',
"Load configuration on boot.",
resty_env.get('APICAST_CONFIGURATION_LOADER') == 'boot'),
resty_env.value('APICAST_CONFIGURATION_LOADER') == 'boot'),
cmd:flag('-l --lazy',
"Load configuration on demand.",
resty_env.get('APICAST_CONFIGURATION_LOADER') == 'lazy')
resty_env.value('APICAST_CONFIGURATION_LOADER') == 'lazy')
)
cmd:option("-i --refresh-interval",
"Cache configuration for N seconds. Using 0 will reload on every request (not for production).",
resty_env.get('APICAST_CONFIGURATION_CACHE'))
resty_env.value('APICAST_CONFIGURATION_CACHE'))

cmd:mutex(
cmd:flag('-v --verbose',
Expand All @@ -200,8 +200,8 @@ local function configure(cmd)
cmd:flag('-q --quiet', "Decrease logging verbosity.")
:count(("0-%s"):format(_M.log_level - 1))
)
cmd:option('--log-level', 'Set log level', resty_env.get('APICAST_LOG_LEVEL') or 'warn')
cmd:option('--log-file', 'Set log file', resty_env.get('APICAST_LOG_FILE') or 'stderr')
cmd:option('--log-level', 'Set log level', resty_env.value('APICAST_LOG_LEVEL') or 'warn')
cmd:option('--log-file', 'Set log file', resty_env.value('APICAST_LOG_FILE') or 'stderr')

cmd:epilog([[
Example: apicast start --dev
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _M.default_environment = 'production' -- default environment name
-- @tfield ?string ca_bundle path to CA store file
-- @table environment.default_config default configuration
_M.default_config = {
ca_bundle = resty_env.get('SSL_CERT_FILE'),
ca_bundle = resty_env.value('SSL_CERT_FILE'),
}

local mt = { __index = _M }
Expand Down Expand Up @@ -59,7 +59,7 @@ function _M.new()
end

local function expand_environment_name(name)
local root = resty_env.get('APICAST_DIR') or pl_path.abspath('.')
local root = resty_env.value('APICAST_DIR') or pl_path.abspath('.')
local pwd = resty_env.value('PWD')

local path = pl_path.abspath(name, pwd)
Expand Down

0 comments on commit 40dfaaa

Please sign in to comment.