Class: Spinach::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/cli.rb

Overview

The cli is a class responsible of handling all the command line interface logic.

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ Cli

Returns a new instance of Cli

Parameters:

  • arguments (Array<String>)

    The command line arguments



12
13
14
# File 'lib/spinach/cli.rb', line 12

def initialize(args = ARGV)
  @args = args
end

Instance Method Details

#feature_filesArray

Uses given args to list the feature files to run. It will find a single feature, features in a folder and subfolders or every feature file in the feature path.

Returns:

  • (Array)

    An array with the feature file names.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/spinach/cli.rb', line 52

def feature_files
  files_to_run = []

  @args.each do |arg|
    if arg.match(/\.feature/)
      if File.exists? arg.gsub(/:\d*/, '')
        files_to_run << arg
      else
        fail! "#{arg} could not be found"
      end
    elsif File.directory?(arg)
      files_to_run << Dir.glob(File.join(arg, '**', '*.feature'))
    elsif arg != "{}"
      fail! "invalid argument - #{arg}"
    end
  end

  if !files_to_run.empty?
    files_to_run.flatten
  else
    Dir.glob(File.join(Spinach.config[:features_path], '**', '*.feature'))
  end
end

#optionsHash

Returns A hash of options separated by its type.

Examples:

Cli.new.options
# => { reporter: { backtrace: true } }

Returns:

  • (Hash)

    A hash of options separated by its type.



40
41
42
# File 'lib/spinach/cli.rb', line 40

def options
  @options ||= parse_options
end

#runtrue, false

Runs all the features.

Returns:

  • (true, false)

    The exit status - true for success, false for failure.



22
23
24
25
26
27
28
29
30
# File 'lib/spinach/cli.rb', line 22

def run
  options

  if Spinach.config.generate
    Spinach::Generators.run(feature_files)
  else
    Spinach::Runner.new(feature_files).run
  end
end