Skip to content

Commit

Permalink
feat(cli) kong prepare cli command to prepare prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Jul 18, 2017
1 parent 1498c45 commit 8bab7f8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions kong-0.10.3-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ build = {
["kong.cmd.reload"] = "kong/cmd/reload.lua",
["kong.cmd.restart"] = "kong/cmd/restart.lua",
["kong.cmd.compile"] = "kong/cmd/compile.lua",
["kong.cmd.prepare"] = "kong/cmd/prepare.lua",
["kong.cmd.migrations"] = "kong/cmd/migrations.lua",
["kong.cmd.health"] = "kong/cmd/health.lua",
["kong.cmd.version"] = "kong/cmd/version.lua",
Expand Down
1 change: 1 addition & 0 deletions kong/cmd/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local cmds = {
health = true,
check = true,
compile = true,
prepare = true,
migrations = true,
version = true,
roar = true
Expand Down
30 changes: 30 additions & 0 deletions kong/cmd/prepare.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local conf_loader = require "kong.conf_loader"
local log = require "kong.cmd.utils.log"

local function execute(args)
local conf = assert(conf_loader(args.conf, {
prefix = args.prefix
}))

local ok, err = prefix_handler.prepare_prefix(conf, args.nginx_conf)
if not ok then
log.verbose("could not prepare Kong")
error(err) -- report to main error handler
end
end

local lapp = [[
Usage: kong prepare [OPTIONS]
Prepares the Kong prefix in the configured prefix directory.
Options:
-c,--conf (optional string) configuration file
-p,--prefix (optional string) override prefix directory
]]

return {
lapp = lapp,
execute = execute
}
23 changes: 23 additions & 0 deletions spec/02-integration/02-cmd/10-prepare_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local helpers = require "spec.helpers"

describe("kong prepare", function()
setup(function()
helpers.clean_prefix()
end)
teardown(function()
helpers.clean_prefix()
end)

it("prepares prefix with default conf/prefix", function()
assert(helpers.kong_exec "prepare")
end)

describe("errors", function()
it("prepare inexistent Kong conf file", function()
local ok, stderr = helpers.kong_exec "prepare --conf foobar.conf"
assert.False(ok)
assert.is_string(stderr)
assert.matches("Error: no file at: foobar.conf", stderr, nil, true)
end)
end)
end)

0 comments on commit 8bab7f8

Please sign in to comment.