Skip to content

Commit

Permalink
Updating CLI for importing
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHall committed Dec 19, 2010
1 parent 9e0eb75 commit 84c1a72
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion bin/jekyll
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.

0 comments on commit 84c1a72

Please sign in to comment.