Module: Lokka::Sh
- Defined in:
- lib/lokka/sh.rb,
lib/lokka/sh/rake.rb,
lib/lokka/sh/color.rb,
lib/lokka/sh/bundler.rb,
lib/lokka/sh/command.rb,
lib/lokka/sh/helpers.rb,
lib/lokka/sh/sinatra.rb,
lib/lokka/sh/forkable.rb
Defined Under Namespace
Modules: Bundler, Color, Command, Forkable, Helpers, Rake, Sinatra
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.initializer ⇒ Object
13
14
15
16
17
18
|
# File 'lib/lokka/sh.rb', line 13
def initializer
::Lokka::Sh::Rake.init
require 'lokka/sh/commands'
begin; load "./lokkashrc"; rescue LoadError; end
end
|
.start ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/lokka/sh.rb', line 20
def start
initializer
Color.with(:cyan) { "Lokka.env: #{::Lokka.env}\n`help` to print help" }
setup_readline
while buf = Readline.readline(prompt, true)
line = buf.strip
next if line.empty?
begin
execute(line)
rescue SystemExit
raise
rescue Exception => e
Color.with(:bg_red) { "#{e.message}\n#{e.backtrace.join("\n")}" }
end
end
setup_readline
end
|
Instance Method Details
#execute(line) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/lokka/sh.rb', line 48
def execute(line)
if command = Command.find(line)
start = Time.now
arg = line.split(/\s+/, 2)[1] rescue nil
command.call(arg)
Color.with(:blue) { "#{Time.now - start}sec" }
else
Color.with(:bg_red) { "Command not found" }
end
end
|
#prompt ⇒ Object
39
40
41
|
# File 'lib/lokka/sh.rb', line 39
def prompt
"%s> " % "lokka-sh(#{File.basename(::Lokka.root)})"
end
|
#setup_readline ⇒ Object
43
44
45
46
|
# File 'lib/lokka/sh.rb', line 43
def setup_readline
Readline.basic_word_break_characters = ""
Readline.completion_proc = Command.completion_proc
end
|