Skip to content
Browse files

Adding granularity to help docs. So help on a specific doc provides m…

…ore details
  • Loading branch information...
1 parent 505b0b0 commit a0e7828b90ce64cf37649f46761d3dd737c7c060 @sreeix committed Mar 7, 2011
View
4 Gemfile
@@ -2,3 +2,7 @@ source :rubygems
gem 'couchrest'
gem 'awesome_print'
gem 'yajl-ruby'
+gem 'ripl'
+gem 'aruba'
+gem 'rspec'
+gem 'bond'
View
17 Gemfile.lock
@@ -1,21 +1,38 @@
GEM
remote: http://rubygems.org/
specs:
+ aruba (0.2.2)
awesome_print (0.3.2)
+ bond (0.4.0)
couchrest (1.0.1)
json (>= 1.4.6)
mime-types (>= 1.15)
rest-client (>= 1.5.1)
+ diff-lcs (1.1.2)
json (1.5.1)
mime-types (1.16)
rest-client (1.6.1)
mime-types (>= 1.16)
+ ripl (0.3.2)
+ bond (~> 0.4.0)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
yajl-ruby (0.8.1)
PLATFORMS
ruby
DEPENDENCIES
+ aruba
awesome_print
+ bond
couchrest
+ ripl
+ rspec
yajl-ruby
View
1 TODO
@@ -1,4 +1,5 @@
Paging
+Temp view.
Validation of inputs.
Decent Editor -> https://github.com/jberkel/interactive_editor
Scripting, piping to couchup.
View
5 lib/couchup/commands/compact.rb
@@ -10,7 +10,10 @@ def run(*params)
end
end
def self.describe
- "Compacts the current database. To preserve space."
+ {:description => "Compacts the current database or specified database. To preserve space.",
+ :usage => "compact [db_name]",
+ :examples =>[ "compact", "compact 'Riders/winners"]
+ }
end
end
end
View
4 lib/couchup/commands/connect.rb
@@ -11,7 +11,9 @@ def run(host = 'localhost', port = 5984)
end
end
def self.describe
- "Connects to the couch server. Takes host and port defaults to 5984"
+ {:description => "Connects to the couch server. Takes host and port defaults to 5984",
+ :usage => 'connect [database], [port]',
+ :examples => ["connect", "connect bigcouch.test.com", "connect 'bigcouch.test.com', 5986"]}
end
end
end
View
8 lib/couchup/commands/create.rb
@@ -28,13 +28,17 @@ def create_view(name)
`#{ENV['EDITOR']} #{tmp_file_path}`
contents = File.open(tmp_file_path).read
- ::Couchup::View.create(name, contents) unless contents.blank?
+ unless contents.blank?
+ ::Couchup::View.create(name, contents)
+ end
file.close
file.unlink
end
def self.describe
- "Creates a new database and switches to the database if using create :database, :foo or a new view if using create :view,'Rider/by_number'"
+ {:description => "Creates a new database and switches to the database",
+ :usage => " create :database | :view , name",
+ :examples => ["create :database, riders", "create :view, 'Riders/test'"]}
end
end
end
View
4 lib/couchup/commands/drop.rb
@@ -11,7 +11,9 @@ def run(*params)
end
def self.describe
- "Drops a either of :database, :view , doc. Use it with drop :database, <dbname> or drop :view, 'Rider/test2', or drop :doc, <id> or even drop :all_docs which removes just the documents"
+ {:description => "Drops specified object from couchdb",
+ :usage => "drop [:database | :view | :doc | :all_docs]",
+ :examples => ["drop :database, 'test'", "drop :view, 'Riders/top_ten'", "drop :doc, '23'", "drop :all_docs"]}
end
end
end
View
5 lib/couchup/commands/get.rb
@@ -8,7 +8,10 @@ def run(id = nil)
end
def self.describe
- "get [id] retuns the document with the id. Just 'get' retrives all documents from the current database"
+ {:description => "Retrives documents from the current database",
+ :usage => "get [:doc], [<id>]",
+ :examples => ["get :doc, '2a663b5936f98fe225d64fcaa89e3281'", "get"]}
+
end
end
end
View
20 lib/couchup/commands/help.rb
@@ -2,17 +2,29 @@ module Couchup
module Commands
class Help
def run(param = nil)
- commands = param.nil? ? Commands.constants : [param.camelize]
- commands.each do |stuff|
+ param.nil? ? show_all : show(param.camelize)
+ nil
+ end
+ def show(command)
+ k = Commands.const_get(command.to_s)
+ ap k.describe
+ end
+
+ def show_all
+ Commands.constants.each do |stuff|
k = Commands.const_get(stuff)
print stuff.underscore
print (stuff.underscore.size > 10) ? "\t" : "\t\t"
- ap k.respond_to?(:describe) ? k.describe : "No Help"
+ ap k.respond_to?(:describe) ? k.describe[:description] : "No Help"
end
+
end
def self.describe
- "Help on the system, 'help :get' will provider help about using get."
+ { :description => "Help on the system",
+ :usage => "help [<command>]",
+ :examples => ["help", "help :get"]}
+
end
end
end
View
5 lib/couchup/commands/map.rb
@@ -9,7 +9,10 @@ def run(*params)
end
def self.describe(p = nil)
- "Runs a view with just the map function and returns the results"
+ {:description => "Runs a view with just the map function and returns the results",
+ :usage => 'map <view_name> [options]',
+ :examples => ["map 'Rider/top_ten'","map 'Rider/top_ten', 10", "map 'Rider/top_ten', {:startkey => '10', :endkey => '20'}","map 'Rider/top_ten', [1,2,3,10]" ]
+ }
end
end
end
View
5 lib/couchup/commands/rename.rb
@@ -10,7 +10,10 @@ def run(*params)
end
def self.describe
- "Renames database or a view both on the same Couch instance. eg. rename :src, :destination"
+ {:description => "Renames database or a view both on the same Couch instance. Replicates to new db and deletes the old. Hence slow.",
+ :usage => "rename <src_database>, <target_database>",
+ :examples => ["rename 'riders_test', 'riders_development'"]
+ }
end
end
end
View
5 lib/couchup/commands/replicate_to.rb
@@ -9,7 +9,10 @@ def run(*params)
end
def self.describe
- "Allows replication to different databases. Try replicate_to 'http://foo.bar.com:5984/billing' :continous"
+ { :description => "Allows replication to different databases",
+ :examples => ["replicate_to :riders_dev", "replicate_to 'http://foo.bar.com:5984/billing', :continous"],
+ :usage => "replicate_to <target_db>, options"
+ }
end
end
View
5 lib/couchup/commands/restart.rb
@@ -6,7 +6,10 @@ def run(*params)
end
def self.describe
- "Restarts the couchdb server. Please be careful with it. It will not prompt you for anything."
+ {:description => "Restarts the couchdb server. Please be careful with it. It will not prompt you for anything.",
+ :examples => ["restart"],
+ :usage => 'restart'
+ }
end
end
end
View
4 lib/couchup/commands/show.rb
@@ -11,7 +11,9 @@ def run(*param)
end
def self.describe
- "show databases if databases is specified or views if views is specified. defaults to databases."
+ {:description => "show databases or views on the current instance/database",
+ :details => "show [:databases | :views], [:design]",
+ :examples => ["show", "show :databases", "show :views"]}
end
end
end
View
5 lib/couchup/commands/use.rb
@@ -12,7 +12,10 @@ def run(database)
end
def self.describe
- "Use provided database"
+ { :description => "Use provided database",
+ :detail => "use <database>",
+ :examples => ["use 'riders'"]
+ }
end
end
end
View
5 lib/couchup/commands/view.rb
@@ -9,7 +9,10 @@ def run(*params)
end
def self.describe(params = nil)
- "Executes the given View. Runs Map and Reduce and retuns the results"
+ {:description => "Executes the given View. Runs Map and Reduce and retuns the results",
+ :usage => "view <view_name> [options]",
+ :examples => ["view 'Riders/top_ten'", "view 'Riders/top_ten', [10,100,200]", "view 'Riders/top_ten', 10", "view 'Riders/top_ten', {:group_level=>2, :group=> true}"]
+ }
end
end
end
View
2 lib/couchup/couchup.rb
@@ -3,6 +3,7 @@ class Couchup
class << self
attr_accessor :port, :host
attr_accessor :last_result
+
def server
@server ||= CouchRest::Server.new("http://#{host}:#{port}")
end
@@ -31,6 +32,7 @@ def delete_doc(id)
doc = database.get(id)
database.delete_doc(doc)
end
+
def delete_all_docs(view_name)
all_docs = view_name.nil? ? all : MapReduce.map(view_name)
all_docs.collect{|d| d["doc"]}.each do |doc|

0 comments on commit a0e7828

Please sign in to comment.
Something went wrong with that request. Please try again.