Skip to content

Commit 0550d40

Browse files
committed
Implement CLI description
1 parent e134199 commit 0550d40

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

exe/matrixeval

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env ruby
22

33
require 'matrixeval/ruby'
4-
puts "Hello, MatrixEval!"
4+
55
Matrixeval.start(ARGV)

exe/meval

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env ruby
22

33
require 'matrixeval/ruby'
4-
puts "Hello, MatrixEval!"
4+
55
Matrixeval.start(ARGV)

lib/matrixeval/ruby/command_line.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
module Matrixeval
44
module Ruby
5+
COMMANDS = ['rake', 'rspec', 'bundle', 'bash']
6+
57
class CommandLine
68

7-
attr_reader :argv
9+
attr_accessor :argv
810

911
def initialize(argv)
1012
@argv = argv
@@ -15,15 +17,17 @@ def init?
1517
end
1618

1719
def all?
18-
argv[0] == 'all'
20+
context_options[:all]
1921
end
2022

2123
def context_options
22-
ParseContextArguments.call(context_arguments)
24+
@context_options ||= ParseContextArguments.call(context_arguments)
2325
end
2426

2527
def context_arguments
26-
argv[0...seperator_index]
28+
arguments = argv[0...seperator_index]
29+
arguments << "-h" if argv.empty?
30+
arguments
2731
end
2832

2933
def rest_arguments
@@ -34,14 +38,10 @@ def rest_arguments
3438

3539
def seperator_index
3640
argv.index do |argument|
37-
seperator_commands.include?(argument)
41+
COMMANDS.include?(argument)
3842
end
3943
end
4044

41-
def seperator_commands
42-
['rake', 'rspec', 'bundle', 'bash']
43-
end
44-
4545
end
4646
end
4747
end

lib/matrixeval/ruby/command_line/parse_context_arguments.rb

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,58 @@ def call
2424

2525
def parse!
2626
OptionParser.new do |opts|
27-
opts.banner = "Usage: meval/matrixeval --[VECTOR_KEY] [VECTOR_CHOICE] [COMMAND] [COMMAND_OPTIONS]"
27+
opts.version = Matrixeval::Ruby::VERSION
28+
opts.program_name = ""
29+
opts.banner = <<~USAGE
30+
Usage:
31+
matrixeval(meval) [OPTIONS] COMMAND
32+
USAGE
33+
34+
opts.separator ""
35+
opts.separator "Options:"
36+
37+
opts.on "-a", "--all", "# Run the COMMAND against all matrix combinations"
2838

2939
Config.vectors.each do |vector|
30-
opts.on("--#{vector.key} [VERSION]", "Set #{vector.key} version")
40+
# short = "-#{vector.short_key}"
41+
long = "--#{vector.key} [VERSION]"
42+
desc = [
43+
"# Run the COMMAND against a specific #{vector.key} version",
44+
"# Options: #{vector.variants.map(&:key).join("/")}",
45+
"# Default: #{vector.default_variant.key}",
46+
"# Customizable"
47+
]
48+
opts.separator ""
49+
opts.on(long, *desc)
50+
end
51+
52+
opts.separator ""
53+
opts.separator "Commands: #{COMMANDS.join("/")} (Customizable)"
54+
55+
opts.separator ""
56+
opts.separator "MatrixEval Options:"
57+
58+
opts.on("-h", "--help", "# Show help") do
59+
puts opts.help
60+
exit
3161
end
62+
63+
opts.on("-v", "--version", "# Show version") do
64+
puts opts.version
65+
exit
66+
end
67+
68+
opts.separator ""
69+
opts.separator "Customizations:"
70+
opts.separator " You can customize all options in matrixeval.yml"
71+
72+
opts.separator ""
73+
opts.separator "Example:"
74+
opts.separator " matrixeval --all bundle install"
75+
opts.separator " matrixeval --ruby 3.0 rspec a_spec.rb"
76+
opts.separator " matrixeval --ruby 3.1 --active_model 7.0 rake test"
77+
opts.separator " matrixeval bash"
78+
3279
end.parse!(context_arguments, into: options)
3380
end
3481

test/matrixeval/ruby/command_line_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ def test_init?
1313
end
1414

1515
def test_all?
16-
command = Matrixeval::Ruby::CommandLine.new(["all", "rake", "test"])
16+
Matrixeval::Ruby::Config::YAML.stubs(:yaml).returns({"matrix" => {}})
17+
18+
command = Matrixeval::Ruby::CommandLine.new(["--all", "rake", "test"])
19+
assert command.all?
20+
21+
command = Matrixeval::Ruby::CommandLine.new(["-a", "rake", "test"])
1722
assert command.all?
1823

1924
command = Matrixeval::Ruby::CommandLine.new(["rake", "test"])

0 commit comments

Comments
 (0)