Class: Siding::CLI

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

Constant Summary collapse

MANAGEMENT_COMMANDS =
%w[start status stop restart doctor init version help --help -h].freeze
ACCELERATED_EXECUTABLES =
%w[rails rake rspec test].freeze
OUT_OF_SCOPE_RAILS_COMMANDS =
%w[dev:cache].freeze
SERVER_COMMANDS =
%w[server s].freeze
DAEMON_FLAGS =
%w[-d --daemon].freeze
REQUEST_TIMEOUT =
5
BOOT_LOG_LINES =
20
BINSTUBS =
%w[rails rake rspec].freeze
BINSTUB_MARKER =
"generated by siding"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, client) ⇒ CLI

Returns a new instance of CLI.



48
49
50
51
# File 'lib/siding/cli.rb', line 48

def initialize(argv, client)
  @argv = argv
  @client = client
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



46
47
48
# File 'lib/siding/cli.rb', line 46

def argv
  @argv
end

#clientObject (readonly)

Returns the value of attribute client.



46
47
48
# File 'lib/siding/cli.rb', line 46

def client
  @client
end

Class Method Details

.accelerated?(argv) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/siding/cli.rb', line 29

def accelerated?(argv)
  executable = argv.first
  return false unless ACCELERATED_EXECUTABLES.include?(executable)
  return rails_accelerated?(argv) if executable == "rails"

  true
end

.management?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
# File 'lib/siding/cli.rb', line 27

def management?(name) = MANAGEMENT_COMMANDS.include?(name)

.rails_accelerated?(argv) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/siding/cli.rb', line 37

def rails_accelerated?(argv)
  command = argv[1]
  return false if OUT_OF_SCOPE_RAILS_COMMANDS.include?(command)
  return false if SERVER_COMMANDS.include?(command) && argv.any? { DAEMON_FLAGS.include?(_1) }

  true
end

Instance Method Details

#runObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/siding/cli.rb', line 53

def run
  command = argv.first
  ret = if ["help", "--help", "-h", nil].include?(command)
    help
  elsif MANAGEMENT_COMMANDS.include?(command)
    send(command)
  else
    unimplemented(command)
  end
  ret.is_a?(Integer) ? ret : 0
end