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) ⇒ HeroShell
constructor
A new instance of HeroShell.
- #run ⇒ Object
Constructor Details
#initialize(herokuApp) ⇒ HeroShell
Returns a new instance of HeroShell.
6 7 8 9 10 11 12 13 |
# File 'lib/heroshell.rb', line 6 def initialize(herokuApp) unless herokuApp puts "switcher <herokuApp>" exit 1 end @app = herokuApp end |
Instance Method Details
#init_completion ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/heroshell.rb', line 15 def init_completion() autocompleted_commands = HerokuCommandsCache.get_commands() Readline.completion_append_character = " " Readline.completion_proc = proc { |s| autocompleted_commands.grep(/^#{Regexp.escape(s)}/) } end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/heroshell.rb', line 23 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 = "heroku #{buf} -a #{@app}" res = system(command) if res Readline::HISTORY.push(buf) else $stderr.puts "Command \"#{command}\" returned non-zero status." end end end end |