Class: Nutella::RunCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/commands/meta/run_command.rb

Overview

This class describes a run command which can be either start or stop. It is mostly a commodity class for code reuse.

Direct Known Subclasses

Compile, Dependencies, Start, Stop

Instance Method Summary collapse

Instance Method Details

#compile_and_dependencies(script, in_progress_message, complete_message) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/commands/meta/run_command.rb', line 64

def compile_and_dependencies( script , in_progress_message, complete_message)
  # If the current directory is not a nutella application, return
  unless Nutella.current_app.exist?
    console.warn 'The current directory is not a nutella application'
    return
  end
  # Run script for all bots
  return unless run_script_for_components_in( "#{Dir.pwd}/bots", script, in_progress_message )
  # Run script for all interfaces
  return unless run_script_for_components_in( "#{Dir.pwd}/interfaces", script, in_progress_message )
  # Output success message
  console.success "All #{complete_message} for #{Nutella.current_app.config['name']}"
end

#parse_cli_parameters(args) ⇒ Hash

Parse the command line parameters

Parameters:

  • args (Array<String>)

    command line arguments passed to the command

Returns:

  • (Hash)

    an hash containing the parameters



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commands/meta/run_command.rb', line 40

def parse_cli_parameters( args )
  begin
    opts = Slop::Options.new
    opts.array '-wo', '--without', 'A list of components NOT to start'
    opts.array '-w', '--with', 'A list of components that needs to be started'
    parser = Slop::Parser.new(opts)
    result = parser.parse(args)
    result.to_hash
  rescue
    raise StandardError.new 'The only supported parameters are --with (-w) and --without (-wo)'
  end
end

#parse_run_id_from(args) ⇒ String

Extracts the run_id from the parameters passed to the command line

Parameters:

  • args (Array<String>)

    command line arguments passed to the command

Returns:

  • (String, String)

    the run_id



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/commands/meta/run_command.rb', line 18

def parse_run_id_from( args )
  # Simple `nutella start/stop` (no args)
  if args.nil? || args.empty?
    return 'default'
  end
  # If the first argument is a parameter, set the run_id to default
  if args[0].start_with? '-'
    run_id =  'default'
  else
    # If the first argument is a run_id, check that it's not 'default' and return it
    # and shift the arguments so we are left with only the parameters in args
    run_id = args[0]
    raise StandardError.new 'Unfortunately you can\'t use `default` as a run_id because it is reserved :(' if run_id=='default'
    args.shift
  end
  run_id
end

Prints a success message if the command completes correctly



55
56
57
58
59
60
61
# File 'lib/commands/meta/run_command.rb', line 55

def print_success_message(app_id, run_id, action)
  if run_id == 'default'
    console.success "Application #{app_id} #{action}!"
  else
    console.success "Application #{app_id}, run #{run_id} #{action}!"
  end
end

#run(args = nil) ⇒ Object



10
11
12
# File 'lib/commands/meta/run_command.rb', line 10

def run (args=nil)
  console.error 'Running the generic RunCommand!!! WAT? https://www.destroyallsoftware.com/talks/wat'
end