Module: CouchShell

Defined in:
lib/couch-shell.rb,
lib/couch-shell/shell.rb,
lib/couch-shell/plugin.rb,
lib/couch-shell/version.rb,
lib/couch-shell/response.rb,
lib/couch-shell/exceptions.rb,
lib/couch-shell/json_value.rb,
lib/couch-shell-plugin/core.rb,
lib/couch-shell/commandline.rb,
lib/couch-shell/ring_buffer.rb,
lib/couch-shell/eval_context.rb,
lib/couch-shell/plugin_utils.rb,
lib/couch-shell-plugin/core_edit.rb,
lib/couch-shell-plugin/core_views.rb,
lib/couch-shell-plugin/core_lucene.rb,
lib/couch-shell-plugin/core_designs.rb

Defined Under Namespace

Modules: PluginClass, PluginUtils Classes: CommandInfo, Commandline, CoreDesignsPlugin, CoreEditPlugin, CoreLucenePlugin, CorePlugin, CoreViewsPlugin, EvalContext, FileToUpload, JsonValue, NoSuchCommand, NoSuchCommandInPlugin, NoSuchPluginRegistered, Plugin, PluginInfo, PluginVariablesObject, Quit, Response, RingBuffer, Shell, ShellUserError, UndefinedVariable, VariableInfo

Constant Summary collapse

JSON_DOC_START_RX =
/\A[ \t\n\r]*[\(\{]/
VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/couch-shell.rb', line 8

def self.run(args)
  server = nil
  path = nil
  user = nil

  begin
    Commandline.new { |cmd|
      cmd.arg { |arg|
        if server.nil?
          server = arg
        elsif path.nil?
          path = arg
        else
          raise Commandline::Error, "too many arguments"
        end
      }
      cmd.opt "-u", "--user=USER",
        "Connect with CouchDB as USER. Password will be asked." do |val|
        user = val
      end
      cmd.opt "-h", "--help", "Show help and exit." do
        STDOUT.puts "Usage: couch-shell [options] [--] [HOSTNAME[:PORT]] [PATH]"
        STDOUT.puts
        STDOUT.puts "Available options:"
        STDOUT.puts cmd.optlisting
        STDOUT.puts
        STDOUT.puts "Example: couch-shell -u admin 127.0.0.1:5984 mydb"
        return 0
      end
    }.process(args)
  rescue Commandline::Error => e
    STDERR.puts e.message
    STDERR.puts "Run `couch-shell -h' for help."
    return 1
  end

  shell = Shell.new(STDIN, STDOUT, STDERR)
  shell.plugin "core"
  shell.plugin "core_edit"
  shell.plugin "core_views"
  shell.plugin "core_designs"
  shell.plugin "core_lucene"
  shell.execute "user #{user}" if user
  shell.execute "server #{server}" if server
  shell.execute "cg #{path}" if path

  shell.read_execute_loop

  0
end