Skip to content

Commit 945505e

Browse files
author
Mateo Chronis
committed
Fix default when list in doc
1 parent 9d5b7b6 commit 945505e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

cli_options/lib/cli_options/docs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ defmodule CliOptions.Docs do
193193
defp maybe_default(schema) do
194194
case schema[:default] do
195195
nil -> ""
196-
default -> "[default: `#{default}`]"
196+
default -> "[default: `#{inspect(default)}`]"
197197
end
198198
end
199199

cli_options/test/cli_options/docs_test.exs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule CliOptions.DocsTest do
3535
"""
3636
* `--verbose` (`boolean`) - [default: `false`]
3737
* `-p, --project...` (`string`) - Required. The project to use
38-
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `parallel`]
38+
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `\"parallel\"`]
3939
* `--with-dash` (`boolean`) - a key with a dash [default: `false`]
4040
"""
4141
|> String.trim()
@@ -51,7 +51,7 @@ defmodule CliOptions.DocsTest do
5151
5252
### Test related options
5353
54-
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `parallel`]
54+
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `\"parallel\"`]
5555
* `--with-dash` (`boolean`) - a key with a dash [default: `false`]
5656
"""
5757
|> String.trim()
@@ -101,7 +101,7 @@ defmodule CliOptions.DocsTest do
101101
102102
### Test related options
103103
104-
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `parallel`]
104+
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `\"parallel\"`]
105105
* `--with-dash` (`boolean`) - a key with a dash [default: `false`]
106106
"""
107107
|> String.trim()
@@ -115,7 +115,7 @@ defmodule CliOptions.DocsTest do
115115
test "with sorting enabled" do
116116
expected =
117117
"""
118-
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `parallel`]
118+
* `--mode` (`string`) - Allowed values: `["parallel", "serial"]`. [default: `\"parallel\"`]
119119
* `-p, --project...` (`string`) - Required. The project to use
120120
* `--verbose` (`boolean`) - [default: `false`]
121121
* `--with-dash` (`boolean`) - a key with a dash [default: `false`]
@@ -175,7 +175,7 @@ defmodule CliOptions.DocsTest do
175175

176176
expected =
177177
"""
178-
* `-v, --var` (`string`) - a var [env: MY_ENV=] [default: `foo`] [aliases: `--var1`, `--var2`]
178+
* `-v, --var` (`string`) - a var [env: MY_ENV=] [default: `\"foo\"`] [aliases: `--var1`, `--var2`]
179179
* `--another` (`integer`) - another var [env: ANOTHER_ENV=]
180180
"""
181181
|> String.trim()
@@ -196,5 +196,32 @@ defmodule CliOptions.DocsTest do
196196

197197
assert CliOptions.docs(schema) == expected
198198
end
199+
200+
test "with default list" do
201+
schema = [
202+
var: [doc: "a var", default: ["foo", "bar"], multiple: true]
203+
]
204+
205+
expected =
206+
"""
207+
* `--var...` (`string`) - a var [default: `[\"foo\", \"bar\"]`]
208+
"""
209+
|> String.trim()
210+
211+
assert CliOptions.docs(schema) == expected
212+
213+
# atom type
214+
schema = [
215+
var: [type: :atom, doc: "a var", default: [:foo, :bar], multiple: true]
216+
]
217+
218+
expected =
219+
"""
220+
* `--var...` (`atom`) - a var [default: `[:foo, :bar]`]
221+
"""
222+
|> String.trim()
223+
224+
assert CliOptions.docs(schema) == expected
225+
end
199226
end
200227
end

0 commit comments

Comments
 (0)