Skip to content

Commit

Permalink
major commit. first functional version
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ryan committed Jul 22, 2011
1 parent fe3c540 commit cbc51c5
Show file tree
Hide file tree
Showing 20 changed files with 389 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .watchr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ watch("spec/.*/*_spec\.rb") do |match|
run_spec match[0]
end

watch("app/(.*/.*)\.rb") do |match|
watch("lib/(.*/.*)\.rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end
16 changes: 13 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
source "http://rubygems.org"
source 'http://rubygems.org'

gem 'mixlib-cli'
gem 'yajl-ruby', :require => 'yajl'
gemspec

group :development, :test do
gem 'rspec', '>= 2.6.0'
gem 'spork', '>= 0.9.0.rc8'
gem 'watchr', '>= 0.7'
gem 'json_spec', '>= 0.5.0'
end

group :doc do
gem 'yard'
end
41 changes: 38 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
PATH
remote: .
specs:
overwatch-cli (0.0.1)
clamp (>= 0.2.2)
formatador (>= 0.2.0)
hirb (= 0.4.5)
rest-client (>= 1.6.3)
yajl-ruby (>= 0.8.2)

GEM
remote: http://rubygems.org/
specs:
mixlib-cli (1.2.0)
clamp (0.2.2)
diff-lcs (1.1.2)
formatador (0.2.0)
hirb (0.4.5)
json (1.5.3)
json_spec (0.5.0)
json (~> 1.0)
rspec (~> 2.0)
mime-types (1.16)
rest-client (1.6.3)
mime-types (>= 1.16)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
spork (0.9.0.rc9)
watchr (0.7)
yajl-ruby (0.8.2)
yard (0.7.2)

PLATFORMS
ruby

DEPENDENCIES
mixlib-cli
yajl-ruby
json_spec (>= 0.5.0)
overwatch-cli!
rspec (>= 2.6.0)
spork (>= 0.9.0.rc8)
watchr (>= 0.7)
yard
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## TODO

* dotfile for configuration of defaults
* expand command set as other overwatch pieces are implemented
* user authentication/authorization (done in the other apps, but we'll need support here)

41 changes: 21 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

Overwatch::Application.load_tasks
# require 'resque/tasks'
# require 'resque_scheduler/tasks'

require 'resque/tasks'
require 'resque_scheduler/tasks'
require 'bundler/gem_tasks'

require 'rspec/core/rake_task'

desc "Run specs"
RSpec::Core::RakeTask.new do |task|
task.pattern = "spec/**/*_spec.rb"
end

desc "Run watchr"
task :watchr do
sh %{bundle exec watchr .watchr}
end

desc "Run spork"
task :spork do
sh %{bundle exec spork}
end

namespace :resque do
task :setup do
require 'resque'
require 'resque_scheduler'
require 'resque/scheduler'

Resque.redis = 'localhost:6379'

Resque.schedule = YAML.load_file(
File.join(File.expand_path(File.dirname(__FILE__)), 'config/schedule.yml')
)

end
end

Bundler.require(:doc)
desc "Generate documentation"
YARD::Rake::YardocTask.new do |t|
t.files = [ 'lib/**/*.rb' ]
end

namespace :overwatch do
namespace :test do
task :snapshot => :environment do
a = Asset.first
a.snapshots.create(:raw_data => {:one => rand(10), :two => { :three => rand(10) }})
a = Resource.first
a.snapshots.create(:data => {:one => rand(10), :two => { :three => rand(10) }})
end
end
end
8 changes: 8 additions & 0 deletions bin/overwatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby

$: << File.expand_path(File.dirname(__FILE__) + "/../lib")

require 'overwatch/cli'
require 'clamp'

Overwatch::CLI::Command.run
14 changes: 0 additions & 14 deletions bin/overwatch-cli

This file was deleted.

9 changes: 8 additions & 1 deletion lib/overwatch/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
require 'mixlib/cli'
require 'yajl'
require 'rest-client'
require 'clamp'
require 'formatador'
require 'hirb'

require 'overwatch/cli/command'
require 'overwatch/cli/helpers'
require 'overwatch/cli/version'


module Overwatch
module CLI

Expand Down
105 changes: 60 additions & 45 deletions lib/overwatch/cli/command.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,71 @@
require 'overwatch/cli/command'
require 'rest-client'
require 'clamp'
require 'formatador'
require 'yajl/json_gem'
require 'overwatch/cli/helpers'
require 'hirb'

module Overwatch
module CLI
module Command
class Command < Clamp::Command
include Helpers

def self.load
Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
require file
end
# Overwatch::CLI::Plugin.load!
end

def self.commands
@@commands ||= {}
end

def self.command_aliases
@@command_aliases ||= {}
end

def self.namespaces
@@namespaces ||= {}
end

def self.register_command(command)
commands[command[:command]] = command
end

def self.register_namespace(namespace)
namespaces[namespace[:name]] = namespace
end

def self.current_command
@current_command
end

def self.current_args
@current_args
end

def self.current_options
@current_options
end

def self.global_options
@global_options ||= []
option ["-v", "--verbose"], :flag, "be verbose"
option "--version", :flag, "show version" do
puts "Overwatch v#{Overwatch::CLI::VERSION} (Codename: Snickelfritz)"
exit(0)
end
subcommand "resource", "Resources" do
option ["-h", "--host"], "HOST", "overwatch-collection server", :default => "localhost"
option ["-p", "--port"], "PORT", "overwatch-collection port", :default => "9001"
option ["-f", "--format"], "[FORMAT]", "format (choices: pretty, json, text)", :default => "pretty"

subcommand "list", "list all resources" do
def execute
options = { :fields => ['id','name', 'api_key'], :format => format }

get("http://#{host}:#{port}/resources", options)
end
end

subcommand "show", "show a specific resource" do
parameter "NAME", "resource name"

option ['-a', '--attributes'], :flag, "list all resource attributes"

def execute
options = { :fields => ['id','name', 'api_key'], :format => format }
get("http://#{host}:#{port}/resources/#{name}", options)
end
end

subcommand "create", "create a new resource" do
parameter "NAME", "resource name"

def execute
options = { :fields => ['id','name', 'api_key'], :format => format }
post("http://#{host}:#{port}/resources", JSON.generate({:name => name}), options)
end

def self.global_option(name, *args)
global_options << { :name => name, :args => args }
end
subcommand "update", "update an existing resource"
subcommand "delete", "delete an existing resource" do
parameter "NAME", "resource name"

def execute
# resource = delete("http://#{host}:#{port}/resources/#{name}")
display_line "[yellow]Resource deleted![/]"
end
end
subcommand "regenerate", "regenerate a resource's API key"
end

subcommand "snapshot", "Snapshots" do
subcommand "show", "show an existing snapshot"
subcommand "create", "create a new snapshot"
subcommand "delete", "delete an existing snapshot"
end
end

end
end
12 changes: 12 additions & 0 deletions lib/overwatch/cli/command/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'clamp'

module Overwatch
module CLI
module Command
class Base

end
end
end

require File.expand_path(File.join(File.dirname(__FILE__), "main"))
14 changes: 14 additions & 0 deletions lib/overwatch/cli/command/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

module Overwatch
module CLI
module Command

class Main < Base

end

end
end
end

# require 'overwatch/cli/command/resource'
11 changes: 11 additions & 0 deletions lib/overwatch/cli/command/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Overwatch
module CLI
module Command
class Resource < Main

end

end
end
end

14 changes: 14 additions & 0 deletions lib/overwatch/cli/command/resource/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Overwatch
module CLI
module Command
class Create < Resource

option ['-n', '--name'], "NAME", "name of resource"

def execute
puts "CREATE"
end
end
end
end
end
11 changes: 11 additions & 0 deletions lib/overwatch/cli/command/resource/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Overwatch
module CLI
module Command

class Resource::Delete < Base

end

end
end
end
12 changes: 12 additions & 0 deletions lib/overwatch/cli/command/resource/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Overwatch
module CLI
module Command
module Resource
class List < Overwatch::CLI::Command::Base

end

end
end
end
end
Loading

0 comments on commit cbc51c5

Please sign in to comment.