Saturday, February 27, 2010

Getting Started with Updates to CouchDocs

‹prev | My Chain | next›

I have been using my couch_docs gem quite a bit while working through my second chain and I must say, it is getting on my nerves. A short list of improvements that I would like includes:
  • Better command line experience.
    • Should default to current directory.
    • Should print help without args / better format
  • Should use the bulk docs
  • Should support the !json and !code macros from couchapp
  • Should support a flag to only work on design docs (mostly for export).
  • Should create the DB if it doesn't already exist
I wrote the gem and I don't remember how to use it. At the very least, I'd like a quick refresher from the command line. Unfortunately this is what I get:
cstrom@whitefall:~/repos/couch_docs$ couch-docs
/home/cstrom/.gem/ruby/1.8/gems/couch_docs-1.0.0/lib/couch_docs/command_line.rb:24:in `run': Unknown command (ArgumentError)
from /home/cstrom/.gem/ruby/1.8/gems/couch_docs-1.0.0/lib/couch_docs/command_line.rb:4:in `run'
from /home/cstrom/.gem/ruby/1.8/gems/couch_docs-1.0.0/bin/couch-docs:8
from /home/cstrom/.gem/ruby/1.8/bin/couch-docs:19:in `load'
from /home/cstrom/.gem/ruby/1.8/bin/couch-docs:19
Bah! That's much too much junk. Even when I ask for help, I get too much path information:
cstrom@whitefall:~/repos/couch_docs$ ./bin/couch-docs -h
/home/cstrom/.gem/ruby/1.8/bin/couch-docs load dir couchdb_uri
/home/cstrom/.gem/ruby/1.8/bin/couch-docs dump couchdb_uri dir
Getting just the basename is trivial as is displaying help info with no command line options:
      when "help", "--help", "-h", nil
puts "#{File.basename($0)} load <dir> <couchdb_uri>"
puts "#{File.basename($0)} dump <couchdb_uri> <dir>"
That makes for much better output:
cstrom@whitefall:~/repos/couch_docs$ ./bin/couch-docs
couch-docs load <dir> <couchdb_uri>
couch-docs dump <couchdb_uri> <dir>
As I have been using couch_docs, I have always loaded from or dumped documents to the current working directory:
cstrom@whitefall:~/tmp/seed$ ./bin/couch-docs dump http://localhost:5984/eee .
Maybe it is silly, but I would just as soon not have to type the dot. Besides, after using couchapp for a while, I have gotten used to not having to type this. It is easy enough to add the current working directory to the options:
    def initialize(args)
@command = args.shift
@options = args
@options.push('.') if @options.size == 1
end

An Unexpected Tangent

I have long since forgotten what I meant to do next, but at some point I tried running rake -T only to be told:
cstrom@whitefall:~/repos/couch_docs$ rake -T
(in /home/cstrom/repos/couch_docs)
rake aborted!
### please install the "bones" gem ###
/home/cstrom/repos/couch_docs/Rakefile:12
(See full trace by running task with --trace)
I installed bones (which I used to create couch_docs in the first place):
cstrom@whitefall:~/repos/couch_docs$ gem install bones
WARNING: Installing to ~/.gem since /var/lib/gems/1.8 and
/var/lib/gems/1.8/bin aren't both writable.
--------------------------
Keep rattlin' dem bones!
--------------------------
Successfully installed rake-0.8.7
Successfully installed little-plugger-1.1.2
Successfully installed loquacious-1.4.2
Successfully installed bones-3.2.1
4 gems installed
When I run rake -T now, I find:
cstrom@whitefall:~/repos/couch_docs$ rake -T
(in /home/cstrom/repos/couch_docs)
rake aborted!
### please install the "bones" gem ###
/home/cstrom/repos/couch_docs/Rakefile:12
(See full trace by running task with --trace)
At first I suspected a require 'rubygems' problem, but the rake task that I am using does require rubygems:
cstrom@whitefall:~/repos/couch_docs$ which rake
/home/cstrom/.gem/ruby/1.8/bin/rake
cstrom@whitefall:~/repos/couch_docs$ cat /home/cstrom/.gem/ruby/1.8/bin/rake
#!/usr/bin/ruby1.8
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end

gem 'rake', version
load Gem.bin_path('rake', 'rake', version)
I eventually trace this back to the wrong version of the bones gem:
cstrom@whitefall:~/repos/couch_docs$ gem list | grep bones
bones (3.2.1)
I had originally used version 2.5 of bones to build my gem. After uninstalling the latest version of bones and installing 2.5, the problem goes away. I am not sure why it is not possible to require 'bones' in version 3.2.1. Something to investigate tomorrow. Maybe.

Day #27

No comments:

Post a Comment