Created
April 11, 2015 20:17
-
-
Save skagedal/29642b9ae255fd6f0c4e to your computer and use it in GitHub Desktop.
mmongo in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# mmongo: An alternative to "meteor mongo" that lets you pass any | |
# arguments to mongo after the -- argument, as in: | |
# mmongo myapp.meteor.com -- myfile.js | |
# | |
# I rewrote this with more features in JavaScript with Node.js: | |
# https://github.com/skagedal/mmongo | |
require 'uri' | |
require 'open3' | |
split_point = ARGV.index('--') | |
if split_point | |
meteor_args = ARGV.take(split_point) | |
mongo_args = ARGV.drop(split_point + 1) | |
else | |
meteor_args = ARGV | |
mongo_args = [] | |
end | |
out, status = Open3.capture2("meteor", "mongo", "--url", *meteor_args) | |
if status.exitstatus != 0 | |
abort("mmongo: meteor mongo --url with arguments #{meteor_args.inspect} failed with status #{status.exitstatus}") | |
end | |
uri = URI(out) | |
port = uri.port ? ":#{uri.port}" : "" | |
cmdline = ["mongo", "#{uri.host}#{port}#{uri.path}"] | |
cmdline += ["-u", uri.user] if uri.user | |
cmdline += ["-p", uri.password] if uri.password | |
cmdline += mongo_args | |
exec(*cmdline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment