Skip to content

Commit

Permalink
Create cli directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo committed Apr 29, 2020
1 parent 96f5cf5 commit 86fa4fd
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 86 deletions.
11 changes: 6 additions & 5 deletions cli.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local cmd = require "command"
local errors = require "errors"
local info = require "info"
local options = require "options"
local cmd = require "cli.command"
local errors = require "cli.errors"
local info = require "cli.info"
local options = require "cli.options"
local translations = require "cli.translations"

local stdout = io.stdout
local translations = require "translations"

local _ENV = {}

Expand Down
10 changes: 5 additions & 5 deletions command.lua → cli/command.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local errors = require "errors"
local iter = require "iterators"
local options = require "options"
local parser = require "parser"
local text = require "text"
local errors = require "cli.errors"
local iter = require "cli.iterators"
local options = require "cli.options"
local parser = require "cli.parser"
local text = require "cli.text"

local _G = _G
local setmetatable = setmetatable
Expand Down
4 changes: 2 additions & 2 deletions errors.lua → cli/errors.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local iter = require "iterators"
local translations = require "translations"
local iter = require "cli.iterators"
local translations = require "cli.translations"

local arg = arg
local panic_with_error = error
Expand Down
8 changes: 4 additions & 4 deletions info.lua → cli/info.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- Information about the program's command line interface

local command = require "command"
local iter = require "iterators"
local text = require "text"
local translations = require "translations"
local command = require "cli.command"
local iter = require "cli.iterators"
local text = require "cli.text"
local translations = require "cli.translations"

local _G = _G
local arg = arg
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions options.lua → cli/options.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local errors = require "errors"
local iter = require "iterators"
local text = require "text"
local translations = require "translations"
local errors = require "cli.errors"
local iter = require "cli.iterators"
local text = require "cli.text"
local translations = require "cli.translations"

local format = string.format
local ipairs = ipairs
Expand Down
8 changes: 4 additions & 4 deletions parser.lua → cli/parser.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local errors = require "errors"
local iter = require "iterators"
local options = require "options"
local text = require "text"
local errors = require "cli.errors"
local iter = require "cli.iterators"
local options = require "cli.options"
local text = require "cli.text"

local arg = arg

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion translations.lua → cli/translations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end
-- `not_expecting` function with 2 arguments corresponding to each of the "%s"
-- placeholders inside the translation string. One uses it like this:
--
-- local translations = require "translations"
-- local translations = require "cli.translations"
--
-- local text = translations.not_expecting("0", "non-zero")
--
Expand Down
74 changes: 37 additions & 37 deletions spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local new_printer = function()
end

insulate("A #program", function()
local errors = require "errors"
local errors = require "cli.errors"

it("should #fill the options' values", function()
_G.arg = {"--value", "17"}
Expand All @@ -38,8 +38,8 @@ insulate("A #program", function()
assert.is_nil(tostring(err))
end
package.loaded.cli = nil
package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
local cli = require "cli"

cli.program {
Expand All @@ -60,8 +60,8 @@ insulate("A #program", function()
assert.is_nil(tostring(err))
end
package.loaded.cli = nil
package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
local cli = require "cli"

cli.program {
Expand All @@ -79,7 +79,7 @@ end)

insulate("A #complete #program", function()
it("should run the `#add` command", function()
local errors = require "errors"
local errors = require "cli.errors"
-- Mock errors.exit_with
errors.exit_with = function(err)
print(tostring(err))
Expand Down Expand Up @@ -153,7 +153,7 @@ end)

insulate("A #complete program", function()
it("should understand subcommands and positionals", function()
local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
print(err)
assert.is_false(true) -- `exit_with` shouldn't be called
Expand Down Expand Up @@ -208,7 +208,7 @@ end)

insulate("A #program", function()
it("should generate a #help message from the spec", function()
local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
assert.is_nil(tostring(err))
end
Expand All @@ -221,8 +221,8 @@ insulate("A #program", function()
[1] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -284,7 +284,7 @@ Arguments:
end)

it("should generate a #help message for a program with #only positionals", function()
local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
assert.is_nil(tostring(err))
end
Expand All @@ -297,8 +297,8 @@ Arguments:
[1] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -333,7 +333,7 @@ Arguments:
end)

it("should generate a #help message for a program with only flags", function()
local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
assert.is_nil(tostring(err))
end
Expand All @@ -346,8 +346,8 @@ Arguments:
[1] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -402,7 +402,7 @@ end)
insulate("A #program with subcommands", function()

it("should generate a #help message from the spec", function()
local errors = require "errors"
local errors = require "cli.errors"
stub(errors, "exit_with")

local printer = new_printer()
Expand All @@ -413,8 +413,8 @@ insulate("A #program with subcommands", function()
[1] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -477,7 +477,7 @@ to get more details about a specific command.
end)

it("should generate a #help message for the specified command", function()
local errors = require "errors"
local errors = require "cli.errors"

local printer = new_printer()
_G.io.stdout = printer
Expand All @@ -492,8 +492,8 @@ to get more details about a specific command.
[2] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -554,7 +554,7 @@ Arguments:
end)

it("should accept a string as argument", function()
local errors = require "errors"
local errors = require "cli.errors"
stub(errors, "exit_with")

local printer = new_printer()
Expand All @@ -565,8 +565,8 @@ Arguments:
[1] = "--help"
}

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down Expand Up @@ -620,7 +620,7 @@ to get more details about a specific command.
end)

insulate("A #program, when finding a #validation #error", function()
local errors = require "errors"
local errors = require "cli.errors"
local cli = require "cli"

local scenarios = {
Expand Down Expand Up @@ -754,8 +754,8 @@ insulate("A #program, when finding a #validation #error", function()
end

_G.arg = scenario.arg
package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
cli = require "cli"

Expand Down Expand Up @@ -792,14 +792,14 @@ if you need some help.
[2] = "--unexpected"
}

local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
assert.are.same(expected, tostring(err))
error("Terminate execution")
end

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand All @@ -814,7 +814,7 @@ if you need some help.
end)

insulate("A #program, when finding a #command #error", function()
local errors = require "errors"
local errors = require "cli.errors"
local cli = require "cli"

local scenarios = {
Expand Down Expand Up @@ -849,8 +849,8 @@ insulate("A #program, when finding a #command #error", function()
end

_G.arg = scenario.arg
package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
cli = require "cli"

Expand Down Expand Up @@ -885,14 +885,14 @@ if you need some help.
[0] = "program",
}

local errors = require "errors"
local errors = require "cli.errors"
errors.exit_with = function(err)
assert.are.same(expected, tostring(err))
error("Terminate execution")
end

package.loaded.parser = nil
package.loaded.command = nil
package.loaded["cli.parser"] = nil
package.loaded["cli.command"] = nil
package.loaded.cli = nil
local cli = require "cli"

Expand Down
Loading

0 comments on commit 86fa4fd

Please sign in to comment.