Permalink
Browse files

Updating CLI for importing

  • Loading branch information...
MattHall committed Dec 15, 2010
1 parent 9e0eb75 commit 84c1a724439a95370ee028b55a65094586a90535
Showing with 81 additions and 1 deletion.
  1. +81 −1 bin/jekyll
  2. 0 lib/jekyll/migrators/{wordpress.com.rb → wordpressdotcom.rb}
@@ -9,7 +9,8 @@ Basic Command Line Usage:
jekyll # . -> ./_site
jekyll <path to write generated site> # . -> <path>
jekyll <path to source> <path to write generated site> # <path> -> <path>
jekyll import <importer name> <options> # imports posts using named import script
Configuration is read from '<source>/_config.yml' but can be overriden
using the following options:
@@ -18,11 +19,37 @@ HELP
require 'optparse'
require 'jekyll'


exec = {}
options = {}
opts = OptionParser.new do |opts|
opts.banner = help

opts.on("--file [PATH]", "File to import from") do |import_file|
options['file'] = import_file
end

opts.on("--dbname [TEXT]", "DB to import from") do |import_dbname|
options['dbname'] = import_dbname
end

opts.on("--user [TEXT]", "Username to use when importing") do |import_user|
options['user'] = import_user
end

opts.on("--pass [TEXT]", "Password to use when importing") do |import_pass|
options['pass'] = import_pass
end

opts.on("--host [HOST ADDRESS]", "Host to import from") do |import_host|
options['host'] = import_host
end

opts.on("--site [SITE NAME]", "Site to import from") do |import_site|
options['site'] = import_site
end


opts.on("--[no-]safe", "Safe mode (default unsafe)") do |safe|
options['safe'] = safe
end
@@ -101,6 +128,59 @@ end
# Read command line options into `options` hash
opts.parse!


# Check for import stuff
if ARGV.size > 0
if ARGV[0] == 'import'
migrator = ARGV[1]

if migrator.nil?
puts "Invalid options. Run `jekyll --help` for assistance."
exit(1)
else
migrator = migrator.downcase
end

cmd_options = []
['file', 'dbname', 'user', 'pass', 'host', 'site'].each do |p|
cmd_options << "\"#{options[p]}\"" unless options[p].nil?
end

# It's import time
puts "Importing..."

# Ideally, this shouldn't be necessary. Maybe parse the actual
# src files for the migrator name?
migrators = {
:posterous => 'Posterous',
:wordpressdotcom => 'WordpressDotCom',
:wordpress => 'Wordpress',
:csv => 'CSV',
:drupal => 'Drupal',
:mephisto => 'Mephisto',
:mt => 'MT',
:textpattern => 'TextPattern',
:typo => 'Typo'
}

app_root = File.join(File.dirname(__FILE__), '..')

require "#{app_root}/lib/jekyll/migrators/#{migrator}"

if Jekyll.const_defined?(migrators[migrator.to_sym])
migrator_class = Jekyll.const_get(migrators[migrator.to_sym])
migrator_class.process(*cmd_options)
else
puts "Invalid migrator. Run `jekyll --help` for assistance."
exit(1)
end

exit(0)
end
end



# Get source and destintation from command line
case ARGV.size
when 0

0 comments on commit 84c1a72

Please sign in to comment.