Class: HeroShell

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

Defined Under Namespace

Classes: HerokuCommandsCache

Instance Method Summary collapse

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_completionObject



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

#runObject



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