diff --git a/spec/clim/dsl_spec/sub_command_1_1_spec.cr b/spec/clim/dsl_spec/sub_command_1_1_spec.cr new file mode 100644 index 00000000..8c3dd034 --- /dev/null +++ b/spec/clim/dsl_spec/sub_command_1_1_spec.cr @@ -0,0 +1,172 @@ +require "../dsl_spec" + +{% begin %} +{% + main_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + main_command_of_clim_library [options] [arguments] + + Options: + + --help Show this help. + + Sub Commands: + + sub_command Sub command with desc. + + + HELP_MESSAGE + + sub_help_message = <<-HELP_MESSAGE + + Sub command with desc. + + Usage: + + sub_command with usage [options] [arguments] + + Options: + + -a ARG, --array=ARG Option test. [type:Array(String)] [default:["default string"]] + --help Show this help. + -v, --version Show version. + + + HELP_MESSAGE +%} + +spec( + spec_class_name: SubCommandWithDescUsageVersionOption, + spec_sub_command_lines: [ + <<-SUB_COMMAND, + sub_command "sub_command" do + desc "Sub command with desc." + usage "sub_command with usage [options] [arguments]" + version "version 1.0.0", short: "-v" + option "-a ARG", "--array=ARG", desc: "Option test.", type: Array(String), default: ["default string"] + run do |options, arguments| + end + end + SUB_COMMAND + ], + spec_desc: "option type spec,", + spec_cases: [ + { + argv: [] of String, + expect_help: {{main_help_message}}, + expect_args: [] of String, + }, + { + argv: ["arg1"], + expect_help: {{main_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["arg1", "arg2"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["arg1", "arg2", "arg3"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["-h"], + exception_message: "Undefined option. \"-h\"", + }, + { + argv: ["--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["--help", "ignore-arg"], + expect_help: {{main_help_message}}, + }, + { + argv: ["ignore-arg", "--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["sub_command"], + expect_help: {{sub_help_message}}, + expect_args: [] of String, + }, + { + argv: ["sub_command", "arg1"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["sub_command", "arg1", "arg2"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["sub_command", "arg1", "arg2", "arg3"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["sub_command", "--version"], + expect_version: "version 1.0.0\n", + }, + { + argv: ["sub_command", "-v"], + expect_version: "version 1.0.0\n", + }, + { + argv: ["sub_command", "--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "--missing-option"], + exception_message: "Undefined option. \"--missing-option\"", + }, + { + argv: ["sub_command", "-m", "arg1"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "arg1", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "-m", "-d"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "--help"], + expect_help: {{sub_help_message}}, + }, + { + argv: ["sub_command", "--help", "ignore-arg"], + expect_help: {{sub_help_message}}, + }, + { + argv: ["sub_command", "ignore-arg", "--help"], + expect_help: {{sub_help_message}}, + }, + ] +) +{% end %} diff --git a/spec/clim/dsl_spec/sub_command_1_2_spec.cr b/spec/clim/dsl_spec/sub_command_1_2_spec.cr new file mode 100644 index 00000000..997d917b --- /dev/null +++ b/spec/clim/dsl_spec/sub_command_1_2_spec.cr @@ -0,0 +1,296 @@ +require "../dsl_spec" + +macro spec_for_sub_sub_commands(spec_class_name, spec_cases) + {% for spec_case, index in spec_cases %} + {% class_name = (spec_class_name.stringify + index.stringify).id %} + + # define dsl + class {{class_name}} < Clim + main_command do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + sub_command "sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + sub_command "sub_sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + end + end + end + end + + # spec + describe "sub sub command," do + describe "if argv is " + {{spec_case["argv"].stringify}} + "," do + it_blocks({{class_name}}, {{spec_case}}) + end + end + {% end %} +end + +{% begin %} +{% + main_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + main_command_of_clim_library [options] [arguments] + + Options: + + --help Show this help. + + Sub Commands: + + sub_command Command Line Interface Tool. + + + HELP_MESSAGE + + sub_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + sub_command [options] [arguments] + + Options: + + --help Show this help. + + Sub Commands: + + sub_sub_command Command Line Interface Tool. + + + HELP_MESSAGE + + sub_sub_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + sub_sub_command [options] [arguments] + + Options: + + --help Show this help. + + + HELP_MESSAGE +%} + +spec_for_sub_sub_commands( + spec_class_name: SubSubCommandOnly, + spec_cases: [ + { + argv: [] of String, + expect_help: {{main_help_message}}, + expect_args: [] of String, + }, + { + argv: ["arg1"], + expect_help: {{main_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["arg1", "arg2"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["arg1", "arg2", "arg3"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["-h"], + exception_message: "Undefined option. \"-h\"", + }, + { + argv: ["--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["--help", "ignore-arg"], + expect_help: {{main_help_message}}, + }, + { + argv: ["ignore-arg", "--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["sub_command"], + expect_help: {{sub_help_message}}, + expect_args: [] of String, + }, + { + argv: ["sub_command", "arg1"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["sub_command", "arg1", "arg2"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["sub_command", "arg1", "arg2", "arg3"], + expect_help: {{sub_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["sub_command", "--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "--missing-option"], + exception_message: "Undefined option. \"--missing-option\"", + }, + { + argv: ["sub_command", "-m", "arg1"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "arg1", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "-m", "-d"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "--help"], + expect_help: {{sub_help_message}}, + }, + { + argv: ["sub_command", "--help", "ignore-arg"], + expect_help: {{sub_help_message}}, + }, + { + argv: ["sub_command", "ignore-arg", "--help"], + expect_help: {{sub_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command"], + expect_help: {{sub_sub_help_message}}, + expect_args: [] of String, + }, + { + argv: ["sub_command", "sub_sub_command", "arg1"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "arg2"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "arg2", "arg3"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["sub_command", "sub_sub_command", "--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "--missing-option"], + exception_message: "Undefined option. \"--missing-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m", "arg1"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m", "-d"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "--help"], + expect_help: {{sub_sub_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command", "--help", "ignore-arg"], + expect_help: {{sub_sub_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command", "ignore-arg", "--help"], + expect_help: {{sub_sub_help_message}}, + }, + ] +) +{% end %} + +macro spec_for_jump_over_sub_sub_command(spec_class_name, spec_cases) + {% for spec_case, index in spec_cases %} + {% class_name = (spec_class_name.stringify + index.stringify).id %} + + # define dsl + class {{class_name}} < Clim + main_command do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + command "sub_command" do + run do |opts, args| + end + command "sub_sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + end + end + command "jump_over_sub_sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + end + end + end + + # spec + describe "jump over sub_sub command," do + describe "if argv is " + {{spec_case["argv"].stringify}} + "," do + it_blocks({{class_name}}, {{spec_case}}) + end + end + {% end %} +end diff --git a/spec/clim/dsl_spec/sub_command_1_3_spec.cr b/spec/clim/dsl_spec/sub_command_1_3_spec.cr new file mode 100644 index 00000000..8306c379 --- /dev/null +++ b/spec/clim/dsl_spec/sub_command_1_3_spec.cr @@ -0,0 +1,261 @@ +require "../dsl_spec" + +macro spec_for_jump_over_sub_sub_command(spec_class_name, spec_cases) + {% for spec_case, index in spec_cases %} + {% class_name = (spec_class_name.stringify + index.stringify).id %} + + # define dsl + class {{class_name}} < Clim + main_command do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + command "sub_command" do + run do |opts, args| + end + command "sub_sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + end + end + command "jump_over_sub_sub_command" do + run do |opts, args| + assert_opts_and_args({{spec_case}}) + end + end + end + end + + # spec + describe "jump over sub_sub command," do + describe "if argv is " + {{spec_case["argv"].stringify}} + "," do + it_blocks({{class_name}}, {{spec_case}}) + end + end + {% end %} +end + +{% begin %} +{% + main_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + main_command_of_clim_library [options] [arguments] + + Options: + + --help Show this help. + + Sub Commands: + + sub_command Command Line Interface Tool. + jump_over_sub_sub_command Command Line Interface Tool. + + + HELP_MESSAGE + + sub_sub_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + sub_sub_command [options] [arguments] + + Options: + + --help Show this help. + + + HELP_MESSAGE + + jump_over_sub_sub_help_message = <<-HELP_MESSAGE + + Command Line Interface Tool. + + Usage: + + jump_over_sub_sub_command [options] [arguments] + + Options: + + --help Show this help. + + + HELP_MESSAGE +%} + +spec_for_jump_over_sub_sub_command( + spec_class_name: JumpOverSubSubCommand, + spec_cases: [ + { + argv: [] of String, + expect_help: {{main_help_message}}, + expect_args: [] of String, + }, + { + argv: ["arg1"], + expect_help: {{main_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["arg1", "arg2"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["arg1", "arg2", "arg3"], + expect_help: {{main_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["-h"], + exception_message: "Undefined option. \"-h\"", + }, + { + argv: ["--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["--help", "ignore-arg"], + expect_help: {{main_help_message}}, + }, + { + argv: ["ignore-arg", "--help"], + expect_help: {{main_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command"], + expect_help: {{sub_sub_help_message}}, + expect_args: [] of String, + }, + { + argv: ["sub_command", "sub_sub_command", "arg1"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "arg2"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "arg2", "arg3"], + expect_help: {{sub_sub_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["sub_command", "sub_sub_command", "--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "--missing-option"], + exception_message: "Undefined option. \"--missing-option\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m", "arg1"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "arg1", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "-m", "-d"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["sub_command", "sub_sub_command", "--help"], + expect_help: {{sub_sub_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command", "--help", "ignore-arg"], + expect_help: {{sub_sub_help_message}}, + }, + { + argv: ["sub_command", "sub_sub_command", "ignore-arg", "--help"], + expect_help: {{sub_sub_help_message}}, + }, + { + argv: ["jump_over_sub_sub_command"], + expect_help: {{jump_over_sub_sub_help_message}}, + expect_args: [] of String, + }, + { + argv: ["jump_over_sub_sub_command", "arg1"], + expect_help: {{jump_over_sub_sub_help_message}}, + expect_args: ["arg1"], + }, + { + argv: ["jump_over_sub_sub_command", "arg1", "arg2"], + expect_help: {{jump_over_sub_sub_help_message}}, + expect_args: ["arg1", "arg2"], + }, + { + argv: ["jump_over_sub_sub_command", "arg1", "arg2", "arg3"], + expect_help: {{jump_over_sub_sub_help_message}}, + expect_args: ["arg1", "arg2", "arg3"], + }, + { + argv: ["jump_over_sub_sub_command", "--help", "-ignore-option"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["jump_over_sub_sub_command", "-ignore-option", "--help"], + exception_message: "Undefined option. \"-ignore-option\"", + }, + { + argv: ["jump_over_sub_sub_command", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["jump_over_sub_sub_command", "--missing-option"], + exception_message: "Undefined option. \"--missing-option\"", + }, + { + argv: ["jump_over_sub_sub_command", "-m", "arg1"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["jump_over_sub_sub_command", "arg1", "-m"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["jump_over_sub_sub_command", "-m", "-d"], + exception_message: "Undefined option. \"-m\"", + }, + { + argv: ["jump_over_sub_sub_command", "--help"], + expect_help: {{jump_over_sub_sub_help_message}}, + }, + { + argv: ["jump_over_sub_sub_command", "--help", "ignore-arg"], + expect_help: {{jump_over_sub_sub_help_message}}, + }, + { + argv: ["jump_over_sub_sub_command", "ignore-arg", "--help"], + expect_help: {{jump_over_sub_sub_help_message}}, + }, + ] +) +{% end %} diff --git a/spec/clim/dsl_spec/sub_command_1_spec.cr b/spec/clim/dsl_spec/sub_command_1_spec.cr deleted file mode 100644 index b20580a5..00000000 --- a/spec/clim/dsl_spec/sub_command_1_spec.cr +++ /dev/null @@ -1,691 +0,0 @@ -require "../dsl_spec" - -{% begin %} -{% - main_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - main_command_of_clim_library [options] [arguments] - - Options: - - --help Show this help. - - Sub Commands: - - sub_command Sub command with desc. - - - HELP_MESSAGE - - sub_help_message = <<-HELP_MESSAGE - - Sub command with desc. - - Usage: - - sub_command with usage [options] [arguments] - - Options: - - -a ARG, --array=ARG Option test. [type:Array(String)] [default:["default string"]] - --help Show this help. - -v, --version Show version. - - - HELP_MESSAGE -%} - -spec( - spec_class_name: SubCommandWithDescUsageVersionOption, - spec_sub_command_lines: [ - <<-SUB_COMMAND, - sub_command "sub_command" do - desc "Sub command with desc." - usage "sub_command with usage [options] [arguments]" - version "version 1.0.0", short: "-v" - option "-a ARG", "--array=ARG", desc: "Option test.", type: Array(String), default: ["default string"] - run do |options, arguments| - end - end - SUB_COMMAND - ], - spec_desc: "option type spec,", - spec_cases: [ - { - argv: [] of String, - expect_help: {{main_help_message}}, - expect_args: [] of String, - }, - { - argv: ["arg1"], - expect_help: {{main_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["arg1", "arg2"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["arg1", "arg2", "arg3"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["-h"], - exception_message: "Undefined option. \"-h\"", - }, - { - argv: ["--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["--help", "ignore-arg"], - expect_help: {{main_help_message}}, - }, - { - argv: ["ignore-arg", "--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["sub_command"], - expect_help: {{sub_help_message}}, - expect_args: [] of String, - }, - { - argv: ["sub_command", "arg1"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["sub_command", "arg1", "arg2"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["sub_command", "arg1", "arg2", "arg3"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["sub_command", "--version"], - expect_version: "version 1.0.0\n", - }, - { - argv: ["sub_command", "-v"], - expect_version: "version 1.0.0\n", - }, - { - argv: ["sub_command", "--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "--missing-option"], - exception_message: "Undefined option. \"--missing-option\"", - }, - { - argv: ["sub_command", "-m", "arg1"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "arg1", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "-m", "-d"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "--help"], - expect_help: {{sub_help_message}}, - }, - { - argv: ["sub_command", "--help", "ignore-arg"], - expect_help: {{sub_help_message}}, - }, - { - argv: ["sub_command", "ignore-arg", "--help"], - expect_help: {{sub_help_message}}, - }, - ] -) -{% end %} - -macro spec_for_sub_sub_commands(spec_class_name, spec_cases) - {% for spec_case, index in spec_cases %} - {% class_name = (spec_class_name.stringify + index.stringify).id %} - - # define dsl - class {{class_name}} < Clim - main_command do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - sub_command "sub_command" do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - sub_command "sub_sub_command" do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - end - end - end - end - - # spec - describe "sub sub command," do - describe "if argv is " + {{spec_case["argv"].stringify}} + "," do - it_blocks({{class_name}}, {{spec_case}}) - end - end - {% end %} -end - -{% begin %} -{% - main_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - main_command_of_clim_library [options] [arguments] - - Options: - - --help Show this help. - - Sub Commands: - - sub_command Command Line Interface Tool. - - - HELP_MESSAGE - - sub_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - sub_command [options] [arguments] - - Options: - - --help Show this help. - - Sub Commands: - - sub_sub_command Command Line Interface Tool. - - - HELP_MESSAGE - - sub_sub_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - sub_sub_command [options] [arguments] - - Options: - - --help Show this help. - - - HELP_MESSAGE -%} - -spec_for_sub_sub_commands( - spec_class_name: SubSubCommandOnly, - spec_cases: [ - { - argv: [] of String, - expect_help: {{main_help_message}}, - expect_args: [] of String, - }, - { - argv: ["arg1"], - expect_help: {{main_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["arg1", "arg2"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["arg1", "arg2", "arg3"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["-h"], - exception_message: "Undefined option. \"-h\"", - }, - { - argv: ["--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["--help", "ignore-arg"], - expect_help: {{main_help_message}}, - }, - { - argv: ["ignore-arg", "--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["sub_command"], - expect_help: {{sub_help_message}}, - expect_args: [] of String, - }, - { - argv: ["sub_command", "arg1"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["sub_command", "arg1", "arg2"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["sub_command", "arg1", "arg2", "arg3"], - expect_help: {{sub_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["sub_command", "--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "--missing-option"], - exception_message: "Undefined option. \"--missing-option\"", - }, - { - argv: ["sub_command", "-m", "arg1"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "arg1", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "-m", "-d"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "--help"], - expect_help: {{sub_help_message}}, - }, - { - argv: ["sub_command", "--help", "ignore-arg"], - expect_help: {{sub_help_message}}, - }, - { - argv: ["sub_command", "ignore-arg", "--help"], - expect_help: {{sub_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command"], - expect_help: {{sub_sub_help_message}}, - expect_args: [] of String, - }, - { - argv: ["sub_command", "sub_sub_command", "arg1"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "arg2"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "arg2", "arg3"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["sub_command", "sub_sub_command", "--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "--missing-option"], - exception_message: "Undefined option. \"--missing-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m", "arg1"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m", "-d"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "--help"], - expect_help: {{sub_sub_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command", "--help", "ignore-arg"], - expect_help: {{sub_sub_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command", "ignore-arg", "--help"], - expect_help: {{sub_sub_help_message}}, - }, - ] -) -{% end %} - -macro spec_for_jump_over_sub_sub_command(spec_class_name, spec_cases) - {% for spec_case, index in spec_cases %} - {% class_name = (spec_class_name.stringify + index.stringify).id %} - - # define dsl - class {{class_name}} < Clim - main_command do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - command "sub_command" do - run do |opts, args| - end - command "sub_sub_command" do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - end - end - command "jump_over_sub_sub_command" do - run do |opts, args| - assert_opts_and_args({{spec_case}}) - end - end - end - end - - # spec - describe "jump over sub_sub command," do - describe "if argv is " + {{spec_case["argv"].stringify}} + "," do - it_blocks({{class_name}}, {{spec_case}}) - end - end - {% end %} -end - -{% begin %} -{% - main_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - main_command_of_clim_library [options] [arguments] - - Options: - - --help Show this help. - - Sub Commands: - - sub_command Command Line Interface Tool. - jump_over_sub_sub_command Command Line Interface Tool. - - - HELP_MESSAGE - - sub_sub_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - sub_sub_command [options] [arguments] - - Options: - - --help Show this help. - - - HELP_MESSAGE - - jump_over_sub_sub_help_message = <<-HELP_MESSAGE - - Command Line Interface Tool. - - Usage: - - jump_over_sub_sub_command [options] [arguments] - - Options: - - --help Show this help. - - - HELP_MESSAGE -%} - -spec_for_jump_over_sub_sub_command( - spec_class_name: JumpOverSubSubCommand, - spec_cases: [ - { - argv: [] of String, - expect_help: {{main_help_message}}, - expect_args: [] of String, - }, - { - argv: ["arg1"], - expect_help: {{main_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["arg1", "arg2"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["arg1", "arg2", "arg3"], - expect_help: {{main_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["-h"], - exception_message: "Undefined option. \"-h\"", - }, - { - argv: ["--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["--help", "ignore-arg"], - expect_help: {{main_help_message}}, - }, - { - argv: ["ignore-arg", "--help"], - expect_help: {{main_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command"], - expect_help: {{sub_sub_help_message}}, - expect_args: [] of String, - }, - { - argv: ["sub_command", "sub_sub_command", "arg1"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "arg2"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "arg2", "arg3"], - expect_help: {{sub_sub_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["sub_command", "sub_sub_command", "--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "--missing-option"], - exception_message: "Undefined option. \"--missing-option\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m", "arg1"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "arg1", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "-m", "-d"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["sub_command", "sub_sub_command", "--help"], - expect_help: {{sub_sub_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command", "--help", "ignore-arg"], - expect_help: {{sub_sub_help_message}}, - }, - { - argv: ["sub_command", "sub_sub_command", "ignore-arg", "--help"], - expect_help: {{sub_sub_help_message}}, - }, - { - argv: ["jump_over_sub_sub_command"], - expect_help: {{jump_over_sub_sub_help_message}}, - expect_args: [] of String, - }, - { - argv: ["jump_over_sub_sub_command", "arg1"], - expect_help: {{jump_over_sub_sub_help_message}}, - expect_args: ["arg1"], - }, - { - argv: ["jump_over_sub_sub_command", "arg1", "arg2"], - expect_help: {{jump_over_sub_sub_help_message}}, - expect_args: ["arg1", "arg2"], - }, - { - argv: ["jump_over_sub_sub_command", "arg1", "arg2", "arg3"], - expect_help: {{jump_over_sub_sub_help_message}}, - expect_args: ["arg1", "arg2", "arg3"], - }, - { - argv: ["jump_over_sub_sub_command", "--help", "-ignore-option"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["jump_over_sub_sub_command", "-ignore-option", "--help"], - exception_message: "Undefined option. \"-ignore-option\"", - }, - { - argv: ["jump_over_sub_sub_command", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["jump_over_sub_sub_command", "--missing-option"], - exception_message: "Undefined option. \"--missing-option\"", - }, - { - argv: ["jump_over_sub_sub_command", "-m", "arg1"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["jump_over_sub_sub_command", "arg1", "-m"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["jump_over_sub_sub_command", "-m", "-d"], - exception_message: "Undefined option. \"-m\"", - }, - { - argv: ["jump_over_sub_sub_command", "--help"], - expect_help: {{jump_over_sub_sub_help_message}}, - }, - { - argv: ["jump_over_sub_sub_command", "--help", "ignore-arg"], - expect_help: {{jump_over_sub_sub_help_message}}, - }, - { - argv: ["jump_over_sub_sub_command", "ignore-arg", "--help"], - expect_help: {{jump_over_sub_sub_help_message}}, - }, - ] -) -{% end %}