lokka-sh 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +47 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/lokka-sh +22 -0
- data/lib/lokka/sh/bundler.rb +22 -0
- data/lib/lokka/sh/color.rb +14 -0
- data/lib/lokka/sh/command.rb +61 -0
- data/lib/lokka/sh/commands.rb +74 -0
- data/lib/lokka/sh/forkable.rb +36 -0
- data/lib/lokka/sh/helpers.rb +60 -0
- data/lib/lokka/sh/rake.rb +42 -0
- data/lib/lokka/sh/sinatra.rb +34 -0
- data/lib/lokka/sh.rb +59 -0
- data/lokka-sh.gemspec +79 -0
- data/spec/lokka/sh/command_spec.rb +73 -0
- data/spec/lokka/sh_spec.rb +5 -0
- data/spec/spec_helper.rb +12 -0
- metadata +131 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rake", "0.8.7"
|
10
|
+
gem "rspec", "~> 2.3.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.5.2"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.5.2)
|
27
|
+
rake (= 0.8.7)
|
28
|
+
rcov
|
29
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 daichi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= lokka-sh
|
2
|
+
|
3
|
+
lokka-sh is a mini shell for CMS Lokka that provides a uniform and quick access to commands.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
$ gem install lokka-sh
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
$ cd your-lokka-app
|
12
|
+
$ lokka-sh
|
13
|
+
|
14
|
+
== Examples
|
15
|
+
|
16
|
+
Execute rake task:
|
17
|
+
|
18
|
+
lokka> rake db:migrate
|
19
|
+
|
20
|
+
Run console:
|
21
|
+
|
22
|
+
lokka> lokka console
|
23
|
+
|
24
|
+
== Commands
|
25
|
+
|
26
|
+
please type help
|
27
|
+
|
28
|
+
== Configuration
|
29
|
+
|
30
|
+
lokka-sh will try to load '~/lokkashrc' as configuration.
|
31
|
+
|
32
|
+
Example:
|
33
|
+
|
34
|
+
# ~/lokkashrc
|
35
|
+
Lokka::Sh::Command.define 'my_command' do |arg|
|
36
|
+
puts "Execute my_command with arg(`#{arg}`)!"
|
37
|
+
end
|
38
|
+
|
39
|
+
== Acknowledge
|
40
|
+
|
41
|
+
This library was allowed to fork jugyo/rails-sh.
|
42
|
+
|
43
|
+
It is gratitude to Mr.jugyo who exhibited the wonderful library.
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2012 daichi. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "lokka-sh"
|
16
|
+
gem.homepage = "http://github.com/daic-h/lokka-sh"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{The Lokka Shell}
|
19
|
+
gem.description = %Q{The Lokka Shell to execute sub commands of rails quickly.}
|
20
|
+
gem.email = "bunny.hop.md@gmail.com"
|
21
|
+
gem.authors = ["Daichi"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rails-sh #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/lokka-sh
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
version = 'v' + File.read(File.expand_path('../../VERSION', __FILE__))
|
4
|
+
puts <<BANNER.gsub("%", "\e[46m \e[0m")
|
5
|
+
|
6
|
+
.%%......%%%%%%..%%..%%..%%..%%...%%%%............%%%%...%%..%%.
|
7
|
+
.%%......%%..%%..%%.%%...%%.%%...%%..%%..........%%......%%..%%.
|
8
|
+
.%%......%%..%%..%%%%....%%%%....%%%%%%..%%%%%%...%%%%...%%%%%%.
|
9
|
+
.%%......%%..%%..%%.%%...%%.%%...%%..%%..............%%..%%..%%.
|
10
|
+
.%%%%%%..%%%%%%..%%..%%..%%..%%..%%..%%...........%%%%...%%..%%.
|
11
|
+
................................................................
|
12
|
+
\e[35m#{version.rjust(63, " ")}\e[0m
|
13
|
+
|
14
|
+
BANNER
|
15
|
+
|
16
|
+
APP_PATH = File.expand_path('./init')
|
17
|
+
puts "\e[34m# require #{APP_PATH}\e[0m"
|
18
|
+
require APP_PATH
|
19
|
+
|
20
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
21
|
+
require 'lokka/sh'
|
22
|
+
Lokka::Sh.start
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Lokka
|
2
|
+
module Sh
|
3
|
+
module Bundler
|
4
|
+
extend Forkable
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def _invoke(line)
|
8
|
+
line ||= 'install'
|
9
|
+
command, *args = line.split(/\s+/)
|
10
|
+
ARGV.clear
|
11
|
+
ARGV.concat args
|
12
|
+
require 'bundler/cli'
|
13
|
+
::Bundler::CLI.new.send(command.to_sym)
|
14
|
+
end
|
15
|
+
|
16
|
+
def sub_commands
|
17
|
+
%w(exec install update open package config check list show console open viz init gem)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lokka
|
2
|
+
module Sh
|
3
|
+
module Color
|
4
|
+
@colors =
|
5
|
+
{ :r_video => 7, :black => 30, :red => 31, :green => 32, :yellow => 33,
|
6
|
+
:blue => 34, :magenta => 35, :cyan => 36, :white => 27, :default => 39,
|
7
|
+
:bg_black => 40, :bg_red => 41, :bg_green => 42, :bg_default => 49 }
|
8
|
+
|
9
|
+
def self.with(name, &block)
|
10
|
+
puts "\e[#{@colors[name.to_sym]}m" + yield + "\e[0m"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Lokka
|
2
|
+
module Sh
|
3
|
+
module Command
|
4
|
+
class << self
|
5
|
+
def commands
|
6
|
+
@commands ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def define(*names, &block)
|
10
|
+
names.each do |name|
|
11
|
+
commands[name.to_sym] = block
|
12
|
+
completions << name.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(line)
|
17
|
+
if name = line.split(/\s+/, 2)[0]
|
18
|
+
commands[name.to_sym]
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def command_names
|
25
|
+
commands.keys
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](name)
|
29
|
+
commands[name.to_sym]
|
30
|
+
end
|
31
|
+
|
32
|
+
def completion_proc
|
33
|
+
lambda { |line|
|
34
|
+
regex = /#{Regexp.quote(line)}/
|
35
|
+
completions.map { |completion|
|
36
|
+
case completion
|
37
|
+
when String
|
38
|
+
completion if completion.match(regex)
|
39
|
+
when Proc
|
40
|
+
completion.call(line)
|
41
|
+
end
|
42
|
+
}.compact
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def completions
|
47
|
+
@completions ||= []
|
48
|
+
end
|
49
|
+
|
50
|
+
def completions=(completions)
|
51
|
+
@completions = completions
|
52
|
+
end
|
53
|
+
|
54
|
+
def clear
|
55
|
+
commands.clear
|
56
|
+
completions.clear
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
include Lokka::Sh
|
2
|
+
|
3
|
+
Command.define 'help' do
|
4
|
+
Color.with(:cyan) do
|
5
|
+
<<HELP
|
6
|
+
help -> print help
|
7
|
+
lokka console -> starting console
|
8
|
+
rake TASK -> execute rake task
|
9
|
+
t, tasks PATTERN -> print rake tasks
|
10
|
+
bundle -> execute bundler command
|
11
|
+
exit -> exit from lokka-sh
|
12
|
+
restart -> restart lokka-sh
|
13
|
+
! -> execute a system command
|
14
|
+
eval -> eval as ruby script
|
15
|
+
TODO: reload
|
16
|
+
HELP
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Command.define 'lokka' do |arg|
|
21
|
+
Lokka::Sh::Sinatra.invoke(arg)
|
22
|
+
end
|
23
|
+
|
24
|
+
Command.define 'rake' do |arg|
|
25
|
+
Lokka::Sh::Rake.invoke(arg)
|
26
|
+
end
|
27
|
+
|
28
|
+
Command.define 'tasks', 't' do |arg|
|
29
|
+
Rake::Task.tasks.each do |task|
|
30
|
+
puts task.name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Lokka::Sh::Rake.task_names.map do |name|
|
35
|
+
Command.completions << "rake #{name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
Command.define 'bundle' do |arg|
|
39
|
+
Lokka::Sh::Bundler.invoke(arg)
|
40
|
+
end
|
41
|
+
|
42
|
+
(Lokka::Sh::Bundler.sub_commands - ['init']).map do |c|
|
43
|
+
Command.completions << "bundle #{c}"
|
44
|
+
end
|
45
|
+
|
46
|
+
Command.define '!' do |arg|
|
47
|
+
system arg
|
48
|
+
end
|
49
|
+
|
50
|
+
Command.define 'eval' do |arg|
|
51
|
+
Color.with(:blue) { "=> #{eval(arg, binding, __FILE__, __LINE__).inspect}" }
|
52
|
+
end
|
53
|
+
|
54
|
+
Command.define 'log' do |arg|
|
55
|
+
Color.with(:r_video) { "Ctrl-C to quit" }
|
56
|
+
system 'tail', '-f', Lokka.root + "tmp/#{(arg || 'development')}.log"
|
57
|
+
end
|
58
|
+
|
59
|
+
Command.completions += %w(development test production).map { |i| "log #{i}" }
|
60
|
+
|
61
|
+
Command.define 'exit' do
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
Command.define 'restart' do
|
66
|
+
puts 'restarting...'
|
67
|
+
exec File.expand_path('../../../../bin/lokka-sh', __FILE__)
|
68
|
+
end
|
69
|
+
|
70
|
+
=begin
|
71
|
+
Command.define 'reload' do
|
72
|
+
Lokka::Sh::Sinatra.reload!
|
73
|
+
end
|
74
|
+
=end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Lokka
|
2
|
+
module Sh
|
3
|
+
module Forkable
|
4
|
+
include Lokka::Sh::Helpers
|
5
|
+
|
6
|
+
def invoke(line, options = {})
|
7
|
+
run_before_fork
|
8
|
+
pid = fork do
|
9
|
+
run_after_fork
|
10
|
+
_invoke(line)
|
11
|
+
end
|
12
|
+
Process.waitpid(pid)
|
13
|
+
end
|
14
|
+
|
15
|
+
def _invoke
|
16
|
+
raise NotImplementedError
|
17
|
+
end
|
18
|
+
|
19
|
+
def before_fork(&block)
|
20
|
+
@before_fork = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_fork(&block)
|
24
|
+
@after_fork = block
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_before_fork(&block)
|
28
|
+
@before_fork.call if @before_fork
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_after_fork(&block)
|
32
|
+
@after_fork.call if @after_fork
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Lokka
|
2
|
+
module Sh
|
3
|
+
module Helpers
|
4
|
+
# copy from pry: https://github.com/pry/pry
|
5
|
+
#
|
6
|
+
# Create scrollable output via less!
|
7
|
+
#
|
8
|
+
# This command runs `less` in a subprocess, and gives you the IO to its STDIN pipe
|
9
|
+
# so that you can communicate with it.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# lesspipe do |less|
|
14
|
+
# 50.times { less.puts "Hi mom!" }
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# The default less parameters are:
|
18
|
+
# * Allow colour
|
19
|
+
# * Don't wrap lines longer than the screen
|
20
|
+
# * Quit immediately (without paging) if there's less than one screen of text.
|
21
|
+
#
|
22
|
+
# You can change these options by passing a hash to `lesspipe`, like so:
|
23
|
+
#
|
24
|
+
# lesspipe(:wrap=>false) { |less| less.puts essay.to_s }
|
25
|
+
#
|
26
|
+
# It accepts the following boolean options:
|
27
|
+
# :color => Allow ANSI colour codes?
|
28
|
+
# :wrap => Wrap long lines?
|
29
|
+
# :always => Always page, even if there's less than one page of text?
|
30
|
+
#
|
31
|
+
def lesspipe(*args)
|
32
|
+
if args.any? and args.last.is_a?(Hash)
|
33
|
+
options = args.pop
|
34
|
+
else
|
35
|
+
options = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
output = args.first if args.any?
|
39
|
+
|
40
|
+
params = []
|
41
|
+
params << "-R" unless options[:color] == false
|
42
|
+
params << "-S" unless options[:wrap] == true
|
43
|
+
params << "-F" unless options[:always] == true
|
44
|
+
if options[:tail] == true
|
45
|
+
params << "+\\>"
|
46
|
+
$stderr.puts "Seeking to end of stream..."
|
47
|
+
end
|
48
|
+
params << "-X"
|
49
|
+
|
50
|
+
IO.popen("less #{params * ' '}", "w") do |less|
|
51
|
+
if output
|
52
|
+
less.puts output
|
53
|
+
else
|
54
|
+
yield less
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module Lokka
|
5
|
+
module Sh
|
6
|
+
module Rake
|
7
|
+
extend Forkable
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def init
|
11
|
+
$stdout = StringIO.new
|
12
|
+
|
13
|
+
before_fork do
|
14
|
+
end
|
15
|
+
after_fork do
|
16
|
+
end
|
17
|
+
|
18
|
+
::Rake.application = ::Rake::Application.new
|
19
|
+
::Rake.application.init
|
20
|
+
::Rake.application.load_rakefile
|
21
|
+
ensure
|
22
|
+
$stdout = STDOUT
|
23
|
+
end
|
24
|
+
|
25
|
+
def _invoke(line)
|
26
|
+
line ||= 'default'
|
27
|
+
name, *args = line.split(/\s+/)
|
28
|
+
args.each do |arg|
|
29
|
+
env, value = arg.split('=')
|
30
|
+
next unless env && !env.empty? && value && !value.empty?
|
31
|
+
ENV[env] = value
|
32
|
+
end
|
33
|
+
::Rake.application[name].invoke
|
34
|
+
end
|
35
|
+
|
36
|
+
def task_names
|
37
|
+
::Rake.application.tasks.map{|t| t.name}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'irb'
|
2
|
+
|
3
|
+
module Lokka
|
4
|
+
module Sh
|
5
|
+
module Sinatra
|
6
|
+
extend Forkable
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def init
|
10
|
+
before_fork do
|
11
|
+
end
|
12
|
+
after_fork do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def _invoke(line)
|
17
|
+
case line
|
18
|
+
when "console"
|
19
|
+
IRB.start(Lokka.root)
|
20
|
+
else
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def reload!
|
26
|
+
end
|
27
|
+
|
28
|
+
def sub_commands
|
29
|
+
%w(console)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/lokka/sh.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'readline'
|
2
|
+
require 'lokka/sh/color'
|
3
|
+
require 'lokka/sh/helpers'
|
4
|
+
require 'lokka/sh/forkable'
|
5
|
+
require 'lokka/sh/sinatra'
|
6
|
+
require 'lokka/sh/rake'
|
7
|
+
require 'lokka/sh/command'
|
8
|
+
require 'lokka/sh/bundler'
|
9
|
+
|
10
|
+
module Lokka
|
11
|
+
module Sh
|
12
|
+
class << self
|
13
|
+
def initializer
|
14
|
+
::Lokka::Sh::Rake.init
|
15
|
+
|
16
|
+
require 'lokka/sh/commands'
|
17
|
+
begin; load "./lokkashrc"; rescue LoadError; end
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
initializer
|
22
|
+
Color.with(:cyan) { "Lokka.env: #{::Lokka.env}\n`help` to print help" }
|
23
|
+
setup_readline
|
24
|
+
while buf = Readline.readline(prompt, true)
|
25
|
+
line = buf.strip
|
26
|
+
next if line.empty?
|
27
|
+
begin
|
28
|
+
execute(line)
|
29
|
+
rescue SystemExit
|
30
|
+
raise
|
31
|
+
rescue Exception => e
|
32
|
+
Color.with(:bg_red) { "#{e.message}\n#{e.backtrace.join("\n")}" }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
setup_readline
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def prompt
|
40
|
+
"%s> " % "lokka-sh(#{File.basename(::Lokka.root)})"
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_readline
|
44
|
+
Readline.basic_word_break_characters = ""
|
45
|
+
Readline.completion_proc = Command.completion_proc
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute(line)
|
49
|
+
if command = Command.find(line)
|
50
|
+
start = Time.now
|
51
|
+
arg = line.split(/\s+/, 2)[1] rescue nil
|
52
|
+
command.call(arg)
|
53
|
+
Color.with(:blue) { "#{Time.now - start}sec" }
|
54
|
+
else
|
55
|
+
Color.with(:bg_red) { "Command not found" }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lokka-sh.gemspec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "lokka-sh"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["daichi"]
|
12
|
+
s.date = "2012-02-01"
|
13
|
+
s.description = "The Lokka Shell to execute sub commands of rails quickly."
|
14
|
+
s.email = "bunny.hop.md@gmail.com"
|
15
|
+
s.executables = ["lokka-sh"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/lokka-sh",
|
30
|
+
"lib/lokka/sh.rb",
|
31
|
+
"lib/lokka/sh/color.rb",
|
32
|
+
"lib/lokka/sh/bundler.rb",
|
33
|
+
"lib/lokka/sh/command.rb",
|
34
|
+
"lib/lokka/sh/commands.rb",
|
35
|
+
"lib/lokka/sh/forkable.rb",
|
36
|
+
"lib/lokka/sh/helpers.rb",
|
37
|
+
"lib/lokka/sh/sinatra.rb",
|
38
|
+
"lib/lokka/sh/rake.rb",
|
39
|
+
"lokka-sh.gemspec",
|
40
|
+
"spec/lokka/sh/command_spec.rb",
|
41
|
+
"spec/lokka/sh_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
s.homepage = "http://github.com/daic-h/lokka-sh"
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = "1.8.11"
|
48
|
+
s.summary = "The Lokka Shell"
|
49
|
+
s.test_files = [
|
50
|
+
"spec/lokka/sh/command_spec.rb",
|
51
|
+
"spec/lokka/sh_spec.rb",
|
52
|
+
"spec/spec_helper.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<rake>, ["= 0.8.7"])
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
63
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
76
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lokka::Sh::Command do
|
4
|
+
before do
|
5
|
+
Lokka::Sh::Command.clear
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'when define a command' do
|
9
|
+
before do
|
10
|
+
@block = lambda {}
|
11
|
+
Lokka::Sh::Command.define('foo', &@block)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'We can find it' do
|
15
|
+
Lokka::Sh::Command.find('foo').should eq(@block)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'We can find nil with wrong name' do
|
19
|
+
Lokka::Sh::Command.find('bar').should eq(nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'We can get command names' do
|
23
|
+
Lokka::Sh::Command.command_names.should =~ [:foo]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'Command.[]' do
|
27
|
+
it 'can get a command' do
|
28
|
+
Lokka::Sh::Command['foo'].should eq(@block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.completions' do
|
34
|
+
context 'when command does not exist' do
|
35
|
+
it 'completions is empty' do
|
36
|
+
Lokka::Sh::Command.completions.should be_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when commands exist' do
|
41
|
+
before do
|
42
|
+
Lokka::Sh::Command.define('foo') {}
|
43
|
+
Lokka::Sh::Command.define('bar') {}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'completions is empty' do
|
47
|
+
Lokka::Sh::Command.completions.should =~ ['foo', 'bar']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.completion_proc' do
|
53
|
+
before do
|
54
|
+
['foo', 'lokka generate', 'rake routes', 'rake spec'].each { |c| Lokka::Sh::Command.completions << c }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'return completions' do
|
58
|
+
Lokka::Sh::Command.completion_proc.call('foo').should =~ ['foo']
|
59
|
+
Lokka::Sh::Command.completion_proc.call('rake').should =~ ['rake routes', 'rake spec']
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with blocks for completion' do
|
63
|
+
before do
|
64
|
+
Lokka::Sh::Command.completions.clear
|
65
|
+
Lokka::Sh::Command.completions << lambda { |line| 'block' }
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'return completions' do
|
69
|
+
Lokka::Sh::Command.completion_proc.call('foo').should =~ ['block']
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'lokka/sh'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lokka-sh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daichi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70274551672860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.7
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70274551672860
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70274551672220 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70274551672220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &70274551671240 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70274551671240
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &70274551670600 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.5.2
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70274551670600
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rcov
|
60
|
+
requirement: &70274551669820 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70274551669820
|
69
|
+
description: The Lokka Shell to execute sub commands of rails quickly.
|
70
|
+
email: bunny.hop.md@gmail.com
|
71
|
+
executables:
|
72
|
+
- lokka-sh
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.rdoc
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- bin/lokka-sh
|
87
|
+
- lib/lokka/sh.rb
|
88
|
+
- lib/lokka/sh/bundler.rb
|
89
|
+
- lib/lokka/sh/color.rb
|
90
|
+
- lib/lokka/sh/command.rb
|
91
|
+
- lib/lokka/sh/commands.rb
|
92
|
+
- lib/lokka/sh/forkable.rb
|
93
|
+
- lib/lokka/sh/helpers.rb
|
94
|
+
- lib/lokka/sh/rake.rb
|
95
|
+
- lib/lokka/sh/sinatra.rb
|
96
|
+
- lokka-sh.gemspec
|
97
|
+
- spec/lokka/sh/command_spec.rb
|
98
|
+
- spec/lokka/sh_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: http://github.com/daic-h/lokka-sh
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -1855965032025882845
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.10
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: The Lokka Shell
|
128
|
+
test_files:
|
129
|
+
- spec/lokka/sh/command_spec.rb
|
130
|
+
- spec/lokka/sh_spec.rb
|
131
|
+
- spec/spec_helper.rb
|