Class: Pairwise::Cli
- Inherits:
-
Object
- Object
- Pairwise::Cli
- Defined in:
- lib/pairwise/cli.rb
Constant Summary collapse
- BUILTIN_FORMATS =
{ 'cucumber' => [Pairwise::Formatter::Cucumber, 'Tables for Cucumber'], 'csv' => [Pairwise::Formatter::Csv, 'Comma seperated values']}
- FORMAT_HELP =
(BUILTIN_FORMATS.keys.sort.map do |key| " #{key}#{' ' * (max - key.length)} : #{BUILTIN_FORMATS[key][1]}" end)
Class Method Summary collapse
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(args, out = STDOUT) ⇒ Cli
constructor
A new instance of Cli.
- #parse! ⇒ Object
Constructor Details
#initialize(args, out = STDOUT) ⇒ Cli
Returns a new instance of Cli.
22 23 24 25 |
# File 'lib/pairwise/cli.rb', line 22 def initialize(args, out = STDOUT) @args, @out = args, out @options = defaults end |
Class Method Details
.execute(args) ⇒ Object
17 18 19 |
# File 'lib/pairwise/cli.rb', line 17 def execute(args) new(args).execute! end |
Instance Method Details
#execute! ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pairwise/cli.rb', line 56 def execute! parse! if inputs = InputFile.load(@filename_with_path) builder = Pairwise::IPO.new(inputs.data, @options) formatter.display(builder.build, inputs.labels) else puts "Error: '#{@filename_with_path}' does not contain the right structure for me to generate the pairwise set!" end end |
#parse! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pairwise/cli.rb', line 27 def parse! @args.extend(::OptionParser::Arguable) @args. do |opts| opts. = ["Usage: pairwise [options] FILE.[yml|csv]", "", "Example:", "pairwise data/inputs.yml", "", "", ].join("\n") opts.on("-k", "--keep-wild-cards", "Don't automatically replace any wild-cards which appear", "in the pairwise data") do @options[:keep_wild_cards] = true end opts.on('-f FORMAT', '--format FORMAT', "How to format pairwise data (Default: cucumber). Available formats:", *FORMAT_HELP) do |format| @options[:format] = format end opts.on_tail("--version", "Show version.") do @out.puts Pairwise::VERSION Kernel.exit(0) end opts.on_tail("-h", "--help", "You're looking at it.") do exit_with_help end end.parse! @filename_with_path = @args[0] unless @args.empty? end |