Class: Divide::CLI
- Inherits:
-
Object
- Object
- Divide::CLI
- Defined in:
- lib/divide/cli.rb
Constant Summary collapse
- OPTIONS =
%w(--tabs)
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #current_app_name ⇒ Object
- #current_directory ⇒ Object
- #error(type) ⇒ Object
- #exit_with_message(message, code = 0) ⇒ Object
- #extract_processes ⇒ Object
- #extracted_processes ⇒ Object
- #extractor ⇒ Object
-
#initialize(argv = []) ⇒ CLI
constructor
A new instance of CLI.
- #show_help ⇒ Object
- #show_version ⇒ Object
- #start_processes(processes) ⇒ Object
- #terminal ⇒ Object
Constructor Details
#initialize(argv = []) ⇒ CLI
Returns a new instance of CLI.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/divide/cli.rb', line 6 def initialize(argv=[]) @options = {} OPTIONS.each { |option| @options[option.sub('--', '').to_sym] = argv.include?(option) } @flags = (argv - OPTIONS).each_slice(2).to_a show_version if argv.grep(/^-v|--version$/).any? show_help if argv.grep(/^-h|--help$/).any? error(:app_not_supported) unless terminal processes = extract_processes start_processes(processes) end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
3 4 5 |
# File 'lib/divide/cli.rb', line 3 def flags @flags end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/divide/cli.rb', line 3 def @options end |
Instance Method Details
#current_app_name ⇒ Object
51 52 53 |
# File 'lib/divide/cli.rb', line 51 def current_app_name @current_app_name ||= TerminalBridge.current_app_name end |
#current_directory ⇒ Object
59 60 61 |
# File 'lib/divide/cli.rb', line 59 def current_directory @current_directory ||= Dir.pwd end |
#error(type) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/divide/cli.rb', line 29 def error(type) errors = { no_procfile: "#{current_directory}: There is no Procfile in this directory", app_not_supported: "#{current_app_name} is not yet supported, please fill in a request https://github.com/EtienneLem/divide/issues", } (errors[type], 1) end |
#exit_with_message(message, code = 0) ⇒ Object
46 47 48 49 |
# File 'lib/divide/cli.rb', line 46 def (, code=0) STDOUT.puts() exit code end |
#extract_processes ⇒ Object
24 25 26 27 |
# File 'lib/divide/cli.rb', line 24 def extract_processes error(:no_procfile) unless extracted_processes extracted_processes.to_a.map { |a| a[1] } end |
#extracted_processes ⇒ Object
55 56 57 |
# File 'lib/divide/cli.rb', line 55 def extracted_processes @extracted_processes ||= extractor.extract_processes! end |
#extractor ⇒ Object
71 72 73 |
# File 'lib/divide/cli.rb', line 71 def extractor @extractor ||= Extractor.new(@flags) end |
#show_help ⇒ Object
42 43 44 |
# File 'lib/divide/cli.rb', line 42 def show_help ("Usage: divide [options]") end |
#show_version ⇒ Object
38 39 40 |
# File 'lib/divide/cli.rb', line 38 def show_version ("Divide #{VERSION}") end |
#start_processes(processes) ⇒ Object
20 21 22 |
# File 'lib/divide/cli.rb', line 20 def start_processes(processes) terminal.exec(processes) end |
#terminal ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/divide/cli.rb', line 63 def terminal @terminal ||= case current_app_name.downcase when 'terminal' then TerminalBridge::Terminal.new(@options) when 'iterm' then TerminalBridge::ITerm.new(@options) else nil end end |