Add initial MigrateCommand

Not all migrators can actually be calld from the comand line. Some require
options which are not passed in and have to be called by other means.
This commit is contained in:
Tom Bell 2012-12-19 17:50:21 +00:00
parent 9c65ceb22d
commit b7944c5274
2 changed files with 63 additions and 0 deletions

View File

@ -43,6 +43,7 @@ command :serve do |c|
c.option '-p', '--port [PORT]', 'Port to listen on'
c.option '-h', '--host [HOST]', 'Host to bind to'
c.option '-b', '--baseurl [URL]', 'Base URL'
c.action do |args, options|
options.default :port => '4000',
:host => '0.0.0.0',
@ -54,3 +55,18 @@ command :serve do |c|
Jekyll::ServeCommand.process(options)
end
end
command :migrate do |c|
c.syntax = 'jekyll migrate <platform> [options]'
c.description = 'Migrate your own blog to Jekyll'
c.option '--file', 'File to migrate from'
c.option '--dbname', 'Database name to migrate from'
c.option '--user', 'Username to use when migrating'
c.option '--pass', 'Password to use when migrating'
c.option '--host', 'Host address to use when migrating'
c.action do |args, options|
Jekyll::MigrateCommand.process(args.first, options)
end
end

View File

@ -0,0 +1,47 @@
module Jekyll
class MigrateCommand < Command
MIGRATORS = {
:csv => 'CSV',
:drupal => 'Drupal',
:enki => 'Enki',
:mephisto => 'Mephisto',
:mt => 'MT',
:posterous => 'Posterous',
:textpattern => 'TextPattern',
:tumblr => 'Tumblr',
:typo => 'Typo',
:wordpressdotcom => 'WordpressDotCom',
:wordpress => 'WordPress'
}
def self.process(migrator, options)
abort 'missing argument. Please specify a migrator' if migrator.nil?
migrator = migrator.downcase
cmd_options = []
[ :file, :dbname, :user, :pass, :host, :site ].each do |p|
cmd_options << "\"#{options[p]}\"" unless options[p].nil?
end
if MIGRATORS.keys.include?(migrator)
app_root = File.expand_path(
File.join(File.dirname(__FILE__), '..', '..', '..')
)
require "#{app_root}/lib/jekyll/migrators/#{migrator}"
if Jekyll.const_defiend?(MIGRATORS[migrator.to_sym])
puts 'Importing...'
migrator_class = Jekyll.const_get(MIGRATORS[migrator.to_sym])
migrator_class.process(*cmd_options)
exit 0
end
end
abort 'invalid migrator. Please specify a valid migrator'
end
end
end