Class: Pairwise::Cli

Inherits:
Object
  • Object
show all
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

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
68
69
70
# File 'lib/pairwise/cli.rb', line 56

def execute!
  parse!
  exit_with_help if @input_file.nil? || @input_file.empty?

  inputs = YAML.load_file(@input_file)
  if valid_inputs?(inputs)
    input_data, input_labels = *parse_input_data!(inputs)

    builder = Pairwise::Builder.new(input_data, @options)

    formatter.display(builder.build, input_labels)
  else
    puts "Error: '#{@input_file}' does not contain the right yaml 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.options do |opts|
    opts.banner = ["Usage: pairwise [options] FILE.yml", "",
    "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!

  @input_file = @args[0] unless @args.empty?
end