Class: HeroShell
- Inherits:
-
Object
- Object
- HeroShell
- Defined in:
- lib/heroshell.rb
Defined Under Namespace
Classes: HerokuCommandsCache
Instance Method Summary collapse
- #init_completion ⇒ Object
-
#initialize(herokuApp, forceCommandsSync) ⇒ HeroShell
constructor
A new instance of HeroShell.
- #run ⇒ Object
Constructor Details
#initialize(herokuApp, forceCommandsSync) ⇒ HeroShell
Returns a new instance of HeroShell.
5 6 7 8 |
# File 'lib/heroshell.rb', line 5 def initialize(herokuApp, forceCommandsSync) @forceCommandSync = forceCommandsSync @app = herokuApp end |
Instance Method Details
#init_completion ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/heroshell.rb', line 10 def init_completion() autocompleted_commands = HerokuCommandsCache.get_commands(@forceCommandSync) Readline.completion_append_character = " " Readline.completer_word_break_characters = "" Readline.completion_proc = proc { |s| autocompleted_commands.grep(/^#{Regexp.escape(s)}/) } end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/heroshell.rb', line 19 def run() init_completion() while buf = Readline.readline("(#{Rainbow(@app).red})> ", false) buf = buf.strip() if buf.empty? next end if buf.start_with?("switch ") switchTo = buf.split(" ")[1] if switchTo @app = switchTo Readline::HISTORY.push(buf) else $stderr.puts "use: \"switch <herokuApp>\" to switch to other app" end else command, arguments = buf.split(/\s+/, 2) res = system("heroku #{command} -a #{@app} #{arguments}") if res Readline::HISTORY.push(buf) else $stderr.puts "Command \"#{command}\" returned non-zero status." end end end puts '' end |