Class: Wire::WireCommands

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

Overview

WireCLI thor command line class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWireCommands

initialize wirecommands object



17
18
19
# File 'lib/wire/cli/cli_commands.rb', line 17

def initialize
  initialize_commands
end

Instance Attribute Details

#commandsObject (readonly)

internal array of commands (as objects)



14
15
16
# File 'lib/wire/cli/cli_commands.rb', line 14

def commands
  @commands
end

Instance Method Details

#initialize_commandsObject

pre-build array of available commands see @commands



23
24
25
26
27
28
29
30
31
32
# File 'lib/wire/cli/cli_commands.rb', line 23

def initialize_commands
  @commands = {
    :init_command => InitCommand.new,
    :validate_command => ValidateCommand.new,
    :verify_command => VerifyCommand.new,
    :spec_command => SpecCommand.new,
    :up_command => UpCommand.new,
    :down_command => DownCommand.new
  } unless @commands
end

#run_down(target_dir) ⇒ Object

run the down command on target_dir model



71
72
73
74
75
76
77
78
# File 'lib/wire/cli/cli_commands.rb', line 71

def run_down(target_dir)
  # :reek:DuplicateCode
  if commands[:down_command].run({ :target_dir => target_dir })
    puts 'OK'.color(:green)
  else
    puts 'ERROR, detected errors'.color(:red)
  end
end

#run_init(target_dir) ⇒ Object

:reek:DuplicateCode run the init command on target_dir model



36
37
38
# File 'lib/wire/cli/cli_commands.rb', line 36

def run_init(target_dir)
  commands[:init_command].run({ :target_dir => target_dir })
end

#run_spec(target_dir, b_run) ⇒ Object

run the spec command on target_dir model



81
82
83
84
85
86
# File 'lib/wire/cli/cli_commands.rb', line 81

def run_spec(target_dir, b_run)
  commands[:spec_command].run({
                                :target_dir => target_dir,
                                :auto_run => b_run
                              })
end

#run_up(target_dir) ⇒ Object

run the up command on target_dir model



61
62
63
64
65
66
67
68
# File 'lib/wire/cli/cli_commands.rb', line 61

def run_up(target_dir)
  # :reek:DuplicateCode
  if commands[:up_command].run({ :target_dir => target_dir })
    puts 'OK'.color(:green)
  else
    puts 'ERROR, detected errors'.color(:red)
  end
end

#run_validate(target_dir) ⇒ Object

:reek:DuplicateCode run the validate command on target_dir model



42
43
44
# File 'lib/wire/cli/cli_commands.rb', line 42

def run_validate(target_dir)
  commands[:validate_command].run({ :target_dir => target_dir })
end

#run_verify(target_dir) ⇒ Object

run the verify command on target_dir model



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wire/cli/cli_commands.rb', line 47

def run_verify(target_dir)
  cmd_ver_obj = commands[:verify_command]
  cmd_ver_obj.run({ :target_dir => target_dir })
  if cmd_ver_obj.findings.size == 0
    puts 'OK, system is conforming to model'.color(:green)
  else
    puts 'ERROR, detected inconsistencies/errors.'.color(:red)
    # cmd_ver_obj.findings.each do |val_error|
    #   puts val_error.to_s
    # end
  end
end