5
5
def test_create_command
7
7
dsl = Cri::CommandDSL.new
10
10
usage 'dunno whatever'
11
11
summary 'does stuff'
12
12
description 'This command does a lot of stuff.'
14
option :a, :aaa, 'opt a', :argument => :optional
14
option :a, :aaa, 'opt a', :argument => :optional, :multiple => true
15
15
required :b, :bbb, 'opt b'
16
16
optional :c, :ccc, 'opt c'
17
17
flag :d, :ddd, 'opt d'
38
38
expected_option_definitions = Set.new([
39
{ :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional, :block => nil },
40
{ :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required, :block => nil },
41
{ :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional, :block => nil },
42
{ :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :block => nil },
43
{ :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :block => nil }
39
{ :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional, :multiple => true, :block => nil },
40
{ :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required, :multiple => false, :block => nil },
41
{ :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional, :multiple => false, :block => nil },
42
{ :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :multiple => false, :block => nil },
43
{ :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :multiple => false, :block => nil }
45
45
actual_option_definitions = Set.new(command.option_definitions)
46
46
assert_equal expected_option_definitions, actual_option_definitions
73
73
expected_option_definitions = Set.new([
74
{ :short => 's', :long => nil, :desc => 'short', :argument => :forbidden, :block => nil },
75
{ :short => nil, :long => 'long', :desc => 'long', :argument => :forbidden, :block => nil }
77
actual_option_definitions = Set.new(command.option_definitions)
78
assert_equal expected_option_definitions, actual_option_definitions
81
def test_optional_options
83
dsl = Cri::CommandDSL.new
74
{ :short => 's', :long => nil, :desc => 'short', :argument => :forbidden, :multiple => false, :block => nil },
75
{ :short => nil, :long => 'long', :desc => 'long', :argument => :forbidden, :multiple => false, :block => nil }
77
actual_option_definitions = Set.new(command.option_definitions)
78
assert_equal expected_option_definitions, actual_option_definitions
83
dsl = Cri::CommandDSL.new
85
flag :f, :flag, 'sample flag option', :multiple => true
86
required :r, :required, 'sample required option', :multiple => true
87
optional :o, :optional, 'sample optional option', :multiple => true
94
expected_option_definitions = Set.new([
95
{ :short => 'f', :long => 'flag', :desc => 'sample flag option', :argument => :forbidden, :multiple => true, :block => nil },
96
{ :short => 'r', :long => 'required', :desc => 'sample required option', :argument => :required, :multiple => true, :block => nil },
97
{ :short => 'o', :long => 'optional', :desc => 'sample optional option', :argument => :optional, :multiple => true, :block => nil },
99
actual_option_definitions = Set.new(command.option_definitions)
100
assert_equal expected_option_definitions, actual_option_definitions
103
def test_required_short_and_long
105
dsl = Cri::CommandDSL.new
106
assert_raises ArgumentError do
108
option nil, nil, 'meh'
84
111
assert_raises ArgumentError do
85
112
dsl.instance_eval do
86
113
flag nil, nil, 'meh'
116
assert_raises ArgumentError do
118
required nil, nil, 'meh'
121
assert_raises ArgumentError do
123
optional nil, nil, 'meh'
91
128
def test_subcommand