Skip to content

Commit

Permalink
Merge pull request #71 from at-grandpa/fix-long-dsl
Browse files Browse the repository at this point in the history
fix long dsl
  • Loading branch information
at-grandpa authored May 16, 2020
2 parents 0854b73 + a675d41 commit 6e1243f
Show file tree
Hide file tree
Showing 83 changed files with 650 additions and 545 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,14 @@ require "clim"
class IoCommand < Clim
main do
run do |opts, args, io|
io.puts "in main_command"
io.puts "in main"
end
end
end
io = IO::Memory.new
IoCommand.start([] of String, io: io)
puts io.to_s # => "in main_command\n"
puts io.to_s # => "in main\n"
```

## Development
Expand Down
40 changes: 20 additions & 20 deletions spec/clim/compile_time_error_spec/compile_time_error_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ describe "Compile time spec, " do
ERROR
end
it "duplicate 'main_command'." do
`crystal run spec/clim/compile_time_error_spec/files/duplicate_main_command.cr --no-color 2>&1`.should eq <<-ERROR
it "duplicate 'main'." do
`crystal run spec/clim/compile_time_error_spec/files/duplicate_main.cr --no-color 2>&1`.should eq <<-ERROR
Showing last frame. Use --error-trace for full trace.
In spec/clim/compile_time_error_spec/files/duplicate_main_command.cr:9:3
In spec/clim/compile_time_error_spec/files/duplicate_main.cr:9:3
9 | main do
^---
Error: Main command is already defined.
ERROR
end
it "without run block in main_command." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_without_run_block.cr --no-color 2>&1`.should eq <<-ERROR
it "without run block in main." do
`crystal run spec/clim/compile_time_error_spec/files/main_without_run_block.cr --no-color 2>&1`.should eq <<-ERROR
Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'main'
Code in spec/clim/compile_time_error_spec/files/main_command_without_run_block.cr:4:3
Code in spec/clim/compile_time_error_spec/files/main_without_run_block.cr:4:3
4 | main do
^
Expand All @@ -51,7 +51,7 @@ describe "Compile time spec, " do
Which expanded to:
> 1 | Clim::Command.command "main_command_of_clim_library" do
> 1 | Clim::Command.command "main_of_clim_library" do
^
Error: 'run' block is not defined.
Expand Down Expand Up @@ -135,35 +135,35 @@ describe "Compile time spec, " do
ERROR
end
it "duplicate 'main_command' in sub command." do
`crystal run spec/clim/compile_time_error_spec/files/duplicate_main_command_in_sub_command.cr --no-color 2>&1`.should eq <<-ERROR
it "duplicate 'main' in sub command." do
`crystal run spec/clim/compile_time_error_spec/files/duplicate_main_in_sub_command.cr --no-color 2>&1`.should eq <<-ERROR
Showing last frame. Use --error-trace for full trace.
In spec/clim/compile_time_error_spec/files/duplicate_main_command_in_sub_command.cr:7:3
In spec/clim/compile_time_error_spec/files/duplicate_main_in_sub_command.cr:7:3
7 | main do
^---
Error: Can not be declared 'main_command' or 'main' as sub command.
Error: Can not be declared 'main' as sub command.
ERROR
end
it "'main_command' is not defined." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_is_not_defined.cr --no-color 2>&1`.should eq <<-ERROR
it "'main' is not defined." do
`crystal run spec/clim/compile_time_error_spec/files/main_is_not_defined.cr --no-color 2>&1`.should eq <<-ERROR
Showing last frame. Use --error-trace for full trace.
In spec/clim/compile_time_error_spec/files/main_command_is_not_defined.cr:4:3
In spec/clim/compile_time_error_spec/files/main_is_not_defined.cr:4:3
4 | sub_command do
^----------
Error: undefined local variable or method 'sub_command' for MyCli.class
4 | sub do
^--
Error: undefined local variable or method 'sub' for MyCli.class
ERROR
end
it "'main_command' with alias name." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_alias_name.cr --no-color 2>&1`.should eq <<-ERROR
it "'main' with alias name." do
`crystal run spec/clim/compile_time_error_spec/files/main_with_alias_name.cr --no-color 2>&1`.should eq <<-ERROR
Showing last frame. Use --error-trace for full trace.
In spec/clim/compile_time_error_spec/files/main_command_with_alias_name.cr:5:5
In spec/clim/compile_time_error_spec/files/main_with_alias_name.cr:5:5
5 | alias_name \"main2\"
^---------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "./../../../../src/clim"

class MyCli < Clim
sub_command do
sub do
run do |opts, args|
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/clim/compile_time_error_spec/stdout_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "./../../spec_helper"

describe "STDOUT spec, " do
it "display main_command help when main command with help_template." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_help_template.cr --no-color -- --help`.should eq <<-DISPLAY
it "display main help when main command with help_template." do
`crystal run spec/clim/compile_time_error_spec/files/main_with_help_template.cr --no-color -- --help`.should eq <<-DISPLAY
command description: Command Line Interface Tool.
command usage: main_command_of_clim_library [options] [arguments]
command usage: main_of_clim_library [options] [arguments]
options:
--help Show this help.
Expand All @@ -21,7 +21,7 @@ describe "STDOUT spec, " do
DISPLAY
end
it "display sub_command help when main command with help_template." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_help_template.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
`crystal run spec/clim/compile_time_error_spec/files/main_with_help_template.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
command description: sub_comand.
command usage: sub_command [options] [arguments]
Expand All @@ -41,7 +41,7 @@ describe "STDOUT spec, " do
DISPLAY
end
it "display sub_sub_command help when main command with help_template." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_help_template.cr --no-color -- sub_command sub_sub_command --help`.should eq <<-DISPLAY
`crystal run spec/clim/compile_time_error_spec/files/main_with_help_template.cr --no-color -- sub_command sub_sub_command --help`.should eq <<-DISPLAY
command description: sub_sub_comand description.
command usage: sub_sub_command [options] [arguments]
Expand All @@ -60,8 +60,8 @@ describe "STDOUT spec, " do
DISPLAY
end
it "display main_command help when main command with help_template part2." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_help_template2.cr --no-color -- --help`.should eq <<-DISPLAY
it "display main help when main command with help_template part2." do
`crystal run spec/clim/compile_time_error_spec/files/main_with_help_template2.cr --no-color -- --help`.should eq <<-DISPLAY
usage: my_cli [--version] [--help] [-P PORT|--port=PORT]
[-h HOST|--host=HOST] [-p PASSWORD|--password=PASSWORD]
Expand Down Expand Up @@ -91,7 +91,7 @@ describe "STDOUT spec, " do
DISPLAY
end
it "display sub_command help when main command with help_template part2." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_with_help_template2.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
`crystal run spec/clim/compile_time_error_spec/files/main_with_help_template2.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
usage: my_cli sub_command [--help] [-t|--tree]
[--html-path=PATH]
Expand All @@ -113,8 +113,8 @@ describe "STDOUT spec, " do
DISPLAY
end
it "display main_command help." do
`crystal run spec/clim/compile_time_error_spec/files/main_command_default_help.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
it "display main help." do
`crystal run spec/clim/compile_time_error_spec/files/main_default_help.cr --no-color -- sub_command --help`.should eq <<-DISPLAY
sub_comand.
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/default_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/required_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/types/bool_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/types/float_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/types/int_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/types/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec/arguments/types/uint_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
4 changes: 2 additions & 2 deletions spec/clim/dsl_spec/help/help_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down Expand Up @@ -149,7 +149,7 @@ spec_for_help(
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down
26 changes: 13 additions & 13 deletions spec/clim/dsl_spec/main_command/main_command_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "../../dsl_spec"
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down Expand Up @@ -123,7 +123,7 @@ spec(
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down Expand Up @@ -240,7 +240,7 @@ spec(
Usage:
main_command_of_clim_library [options] [arguments]
main_of_clim_library [options] [arguments]
Options:
Expand Down Expand Up @@ -359,7 +359,7 @@ spec(
Usage:
main_command with usage [options] [arguments]
main with usage [options] [arguments]
Options:
Expand All @@ -373,7 +373,7 @@ spec(
spec_class_name: MainCommandWithUsage,
spec_dsl_lines: [
"desc \"Main command with desc.\"",
"usage \"main_command with usage [options] [arguments]\"",
"usage \"main with usage [options] [arguments]\"",
],
spec_desc: "main command,",
spec_cases: [
Expand Down Expand Up @@ -477,7 +477,7 @@ spec(
Usage:
main_command with usage [options] [arguments]
main with usage [options] [arguments]
Options:
Expand All @@ -490,7 +490,7 @@ spec(
spec(
spec_class_name: MainCommandWithUsageConst,
spec_class_define_lines: [
"USAGE_CONST = \"main_command with usage [options] [arguments]\"",
"USAGE_CONST = \"main with usage [options] [arguments]\"",
],
spec_dsl_lines: [
"desc \"Main command with desc.\"",
Expand Down Expand Up @@ -598,7 +598,7 @@ spec(
Usage:
main_command with usage [options] [arguments]
main with usage [options] [arguments]
Options:
Expand All @@ -614,7 +614,7 @@ spec(
spec_dsl_lines: [
"version \"Version 0.9.9\"",
"desc \"Main command with desc.\"",
"usage \"main_command with usage [options] [arguments]\"",
"usage \"main with usage [options] [arguments]\"",
],
spec_desc: "main command,",
spec_cases: [
Expand Down Expand Up @@ -661,7 +661,7 @@ spec(
Usage:
main_command with usage [options] [arguments]
main with usage [options] [arguments]
Options:
Expand All @@ -677,7 +677,7 @@ spec(
spec_dsl_lines: [
"version Clim::VERSION",
"desc \"Main command with desc.\"",
"usage \"main_command with usage [options] [arguments]\"",
"usage \"main with usage [options] [arguments]\"",
],
spec_desc: "main command,",
spec_cases: [
Expand Down Expand Up @@ -724,7 +724,7 @@ spec(
Usage:
main_command with usage [options] [arguments]
main with usage [options] [arguments]
Options:
Expand All @@ -740,7 +740,7 @@ spec(
spec_dsl_lines: [
"version \"Version 0.9.9\", short: \"-v\"",
"desc \"Main command with desc.\"",
"usage \"main_command with usage [options] [arguments]\"",
"usage \"main with usage [options] [arguments]\"",
],
spec_desc: "main command,",
spec_cases: [
Expand Down
Loading

0 comments on commit 6e1243f

Please sign in to comment.