Skip to content

Commit

Permalink
Major rewrite of the CLI and added stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Farmer committed Dec 17, 2010
1 parent cbe6a93 commit 1dd0e71
Show file tree
Hide file tree
Showing 21 changed files with 633 additions and 164 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.gem
.rvmrc*

18 changes: 18 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# A sample Gemfile
source "http://rubygems.org"

gem "terminal-table"
path "/Users/mikefarmer/Dropbox/Kynetx/oss/am_api_gem" do
gem "kynetx_am_api"
end
gem "sinatra"
gem "launchy"
gem "awesome_print"
gem "thor"

group :development do
gem "rspec", ">= 2.0.0"
gem "guard-rspec"
gem "rb-fsevent"
gem "growl"
end
60 changes: 60 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
PATH
remote: /Users/mikefarmer/Dropbox/Kynetx/oss/am_api_gem
specs:
kynetx_am_api (0.1.29)
json
multipart-post
oauth

GEM
remote: http://rubygems.org/
specs:
awesome_print (0.3.1)
configuration (1.2.0)
diff-lcs (1.1.2)
growl (1.0.3)
guard (0.2.2)
open_gem (~> 1.4.2)
thor (~> 0.14.3)
guard-rspec (0.1.9)
guard (>= 0.2.2)
json (1.4.6)
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
multipart-post (1.0.1)
oauth (0.4.4)
open_gem (1.4.2)
launchy (~> 0.3.5)
rack (1.2.1)
rake (0.8.7)
rb-fsevent (0.3.9)
rspec (2.3.0)
rspec-core (~> 2.3.0)
rspec-expectations (~> 2.3.0)
rspec-mocks (~> 2.3.0)
rspec-core (2.3.0)
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
terminal-table (1.4.2)
thor (0.14.6)
tilt (1.1)

PLATFORMS
ruby

DEPENDENCIES
awesome_print
growl
guard-rspec
kynetx_am_api!
launchy
rb-fsevent
rspec (>= 2.0.0)
sinatra
terminal-table
thor
36 changes: 6 additions & 30 deletions bin/krl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
#!/usr/bin/env ruby
require 'rubygems'
#$DEBUG = true
LIB_DIR = File.dirname(__FILE__) + "/../lib/"

COMMANDS = {
"help" => lambda { |args| require LIB_DIR + 'help'; KRL_CMD::Help.go },
"apps" => lambda { |args| require LIB_DIR + 'apps'; KRL_CMD::Apps.go },
"checkout" => lambda { |args| require LIB_DIR + 'checkout'; KRL_CMD::Checkout.go(args) },
"create" => lambda { |args| require LIB_DIR + 'create'; KRL_CMD::Create.go(args) },
"update" => lambda { |args| require LIB_DIR + 'update'; KRL_CMD::Update.go(args) },
"versions" => lambda { |args| require LIB_DIR + 'versions'; KRL_CMD::Versions.go(args) },
"deploy" => lambda { |args| require LIB_DIR + 'deploy'; KRL_CMD::Deploy.go(args) },
"commit" => lambda { |args| require LIB_DIR + 'commit'; KRL_CMD::Commit.go(args) },
"show" => lambda { |args| require LIB_DIR + 'show'; KRL_CMD::Show.go(args) },
"note" => lambda { |args| require LIB_DIR + 'note'; KRL_CMD::Note.go(args) },
"check" => lambda { |args| require LIB_DIR + 'check'; KRL_CMD::Check.go(args) },
"generate" => lambda { |args| require LIB_DIR + 'generate'; KRL_CMD::Generate.go(args) },
"test" => lambda { |args| require LIB_DIR + 'test'; KRL_CMD::Test.go(args) },
"info" => lambda { |args| require LIB_DIR + 'info'; KRL_CMD::Info.go(args) }
}
require 'bundler/setup'
require 'thor'
require 'ap'

banner = "Usage: krl <command> <args>\nUse 'krl help' for more information."
#$DEBUG = true

cmd = ARGV.shift
if COMMANDS.keys.include? cmd
begin
COMMANDS[cmd].call(ARGV)
rescue Exception => e
puts "Error: #{e.message}"
end
else
puts banner
end
require File.dirname(__FILE__) + "/../lib/cli"
KRL_CMD::CLI.start
1 change: 1 addition & 0 deletions bin/krl-connect
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require "rubygems"
require 'bundler/setup'
require "sinatra/base"
require "yaml"
require "kynetx_am_api"
Expand Down
12 changes: 9 additions & 3 deletions krl.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rake'

Gem::Specification.new do |s|
s.name = %q{krl}
s.version = "0.1.68"
s.version = "0.2.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael Farmer, Cid Dennis"]
Expand Down Expand Up @@ -30,23 +30,29 @@ Gem::Specification.new do |s|
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<kynetx_am_api>, [">= 0.1.29"])
s.add_runtime_dependency(%q<kynetx_am_api>, [">= 0.1.30"])
s.add_runtime_dependency(%q<terminal-table>, [">= 0"])
s.add_runtime_dependency(%q<sinatra>, [">= 1.0"])
s.add_runtime_dependency(%q<launchy>, [">= 0.3.7"])
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
s.add_runtime_dependency(%q<thor>, [">= 0.14.6"])
s.add_development_dependency('rspec')
else
s.add_dependency(%q<kynetx_am_api>, [">= 0.1.29"])
s.add_dependency(%q<kynetx_am_api>, [">= 0.1.30"])
s.add_dependency(%q<terminal-table>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 1.0"])
s.add_dependency(%q<launchy>, [">= 0.3.7"])
s.add_dependency(%q<awesome_print>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0.14.6"])
s.add_development_dependency('rspec')
end
else
s.add_dependency(%q<kynetx_am_api>, [">= 0.1.29"])
s.add_dependency(%q<terminal-table>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 1.0"])
s.add_dependency(%q<launchy>, [">= 0.3.7"])
s.add_dependency(%q<awesome_print>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0.14.6"])
s.add_development_dependency('rspec')
end
end
4 changes: 1 addition & 3 deletions lib/apps.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module KRL_CMD
class Apps
def self.go
require LIB_DIR + 'user'
require LIB_DIR + 'common'
user = User.new
KRL_COMMON::pretty_table(user.applications["apps"], [
{:field => "Ruleset ID", :value => lambda { |r| r["appid"] }},
Expand All @@ -11,4 +9,4 @@ def self.go
])
end
end
end
end
11 changes: 5 additions & 6 deletions lib/check.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
require 'json'
module KRL_CMD
class Check
def self.go(args)
require LIB_DIR + 'common'
require 'json'
def self.go(options)
app = KRL_COMMON::get_app
krl_file = File.join(Dir.pwd, app.application_id + ".krl")
raise "Cannot find .krl file." unless File.exists?(krl_file)
if args.to_s == ""
apiurl = "http://krl.kobj.net/manage/parse/ruleset"
if options["parser"]
apiurl = options["parser"]
else
apiurl = args.to_s
apiurl = "http://krl.kobj.net/manage/parse/ruleset"
end
apiargs = { "krl" => File.open(krl_file, 'r') { |f| f.read } }
validateresponse = KRL_COMMON::long_post_form(URI.parse(apiurl), apiargs).body.to_s
Expand Down
79 changes: 57 additions & 22 deletions lib/checkout.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
require LIB_DIR + 'user'
require 'fileutils'

module KRL_CMD
class Checkout
def self.go(args)
require LIB_DIR + 'common'

def self.go(ruleset, options)
begin
c = self.new(ruleset, options)
c.checkout
rescue Exception => e
puts e.message
ap e.backtrace if $DEBUG
end
end

def initialize(ruleset, options)
@user = User.new
@ruleset = ruleset
@include_title = options["title"]
@all = options["all"]
app = KRL_COMMON::get_app rescue nil
raise "You are already in an application: #{app.application_id}" if app

ruleset_id = args.to_s
puts "Checking out: #{ruleset_id}"
raise "Please specify a ruleset id." if ruleset_id.empty?
root_dir = Dir.pwd + "/#{ruleset_id}"
raise "Directory already exists." if File.exists?(root_dir)
user = User.new
app = user.find_application({:application_id => ruleset_id})

puts "Creating directory: #{root_dir}"
FileUtils.mkdir root_dir
app_details = {
:name => app.name,
:ruleset_id => app.application_id,
:role => user.owns_current? ? "owner" : "developer"
}
File.open(root_dir + "/.app", "w") { |f| f.print(app_details.to_yaml) }
File.open(root_dir + "/#{ruleset_id}.krl", "w") { |f| f.print(app.krl) }
raise "You are already in an application directory: #{app.application_id}" if app
end

def checkout

if @all
@user.applications["apps"].each do |app|
begin
@ruleset = app["appid"]
do_checkout
rescue => e
puts e.message
end
end
else
do_checkout
end


end

private

def do_checkout
app = @user.find_application({:application_id => @ruleset})
if app
dir_name = @include_title && app.name ? "#{@ruleset}-#{app.name}" : @ruleset
puts "Checking out: #{dir_name}"
root_dir = Dir.pwd + "/#{dir_name}"
raise "Directory already exists (#{root_dir})." if File.exists?(root_dir)

puts "Creating directory: #{root_dir}"
FileUtils.mkdir root_dir
app_details = {
:name => app.name,
:ruleset_id => app.application_id,
:role => @user.owns_current? ? "owner" : "developer"
}
File.open(root_dir + "/.app", "w") { |f| f.print(app_details.to_yaml) }
File.open(root_dir + "/#{app.application_id}.krl", "w") { |f| f.print(app.krl) }
else
puts "Unable to find ruleset #{@ruleset}. You probably don't have permission to check it out."
end
end
end
end
Loading

0 comments on commit 1dd0e71

Please sign in to comment.