Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
redef class CmdComment
redef fun parser_init(mentity_name, options) do
redef class CmdComment
redef fun parser_init(mentity_name, options) do
- full_doc = not options.has_key("only-synopsis")
- fallback = not options.has_key("no-fallback")
+ var opt_full_doc = options.opt_bool("only-synopsis")
+ if opt_full_doc != null then full_doc = not opt_full_doc
+ var opt_fallback = options.opt_bool("no-fallback")
+ if opt_fallback != null then fallback = not opt_fallback
var opt_format = options.opt_string("format")
if opt_format != null then format = opt_format
return super
var opt_format = options.opt_string("format")
if opt_format != null then format = opt_format
return super
redef class CmdAncestors
redef fun parser_init(mentity_name, options) do
redef class CmdAncestors
redef fun parser_init(mentity_name, options) do
- if options.has_key("parents") and options["parents"] == "false" then parents = false
+ var opt_parents = options.opt_bool("no-parents")
+ if opt_parents != null then parents = not opt_parents
return super
end
end
redef class CmdDescendants
redef fun parser_init(mentity_name, options) do
return super
end
end
redef class CmdDescendants
redef fun parser_init(mentity_name, options) do
- if options.has_key("children") and options["children"] == "false" then children = false
+ var opt_children = options.opt_bool("no-children")
+ if opt_children != null then children = not opt_children
if not value.is_int then return null
return value.to_i
end
if not value.is_int then return null
return value.to_i
end
+
+ # Get option value as bool
+ #
+ # Return `true` if the value with that `key` is empty or equals `"true"`.
+ # Return `false` if the value with that `key` equals `"false"`.
+ # Return `null` in any other case.
+ fun opt_bool(key: String): nullable Bool do
+ if not has_key(key) then return null
+ var value = self[key]
+ if value.is_empty or value == "true" then return true
+ if value == "false" then return false
+ return null
+ end
fun test_cmd_parser_ancestors_without_parents is test do
var parser = new CommandParser(test_model, test_main, test_builder, test_catalog)
fun test_cmd_parser_ancestors_without_parents is test do
var parser = new CommandParser(test_model, test_main, test_builder, test_catalog)
- var cmd = parser.parse("ancestors: test_prog::Warrior | parents: false")
+ var cmd = parser.parse("ancestors: test_prog::Warrior | no-parents")
assert cmd isa CmdAncestors
assert parser.error == null
assert cmd.results.as(not null).length == 1
assert cmd isa CmdAncestors
assert parser.error == null
assert cmd.results.as(not null).length == 1
fun test_cmd_parser_descendants_without_children is test do
var parser = new CommandParser(test_model, test_main, test_builder, test_catalog)
fun test_cmd_parser_descendants_without_children is test do
var parser = new CommandParser(test_model, test_main, test_builder, test_catalog)
- var cmd = parser.parse("descendants: Object | children: false")
+ var cmd = parser.parse("descendants: Object | no-children: true")
assert cmd isa CmdDescendants
assert parser.error == null
assert cmd.results.as(not null).length == 9
assert cmd isa CmdDescendants
assert parser.error == null
assert cmd.results.as(not null).length == 9
fun test_ancestors is test do
var parser = new CommandParser(test_model, test_main, test_builder)
fun test_ancestors is test do
var parser = new CommandParser(test_model, test_main, test_builder)
- parser.execute("ancestors: Warrior | parents: true", true)
+ parser.execute("ancestors: Warrior | no-parents: false", true)
end
fun test_ancestors_without_parents is test do
var parser = new CommandParser(test_model, test_main, test_builder)
end
fun test_ancestors_without_parents is test do
var parser = new CommandParser(test_model, test_main, test_builder)
- parser.execute("ancestors: Warrior | parents: false", true)
+ parser.execute("ancestors: Warrior | no-parents", true)
end
fun test_parents is test do
end
fun test_parents is test do
fun test_descendants_without_children is test do
var parser = new CommandParser(test_model, test_main, test_builder)
fun test_descendants_without_children is test do
var parser = new CommandParser(test_model, test_main, test_builder)
- parser.execute("descendants: Career | children: false", true)
+ parser.execute("descendants: Career | no-children", true)