From b7944c527496a107e4afecb92735604d5cbbe162 Mon Sep 17 00:00:00 2001 From: Tom Bell Date: Wed, 19 Dec 2012 17:50:21 +0000 Subject: [PATCH] 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. --- bin/jekyll2 | 16 ++++++++++++ lib/jekyll/commands/migrate.rb | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 lib/jekyll/commands/migrate.rb diff --git a/bin/jekyll2 b/bin/jekyll2 index 29030c47..3df10e4f 100755 --- a/bin/jekyll2 +++ b/bin/jekyll2 @@ -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 [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 diff --git a/lib/jekyll/commands/migrate.rb b/lib/jekyll/commands/migrate.rb new file mode 100644 index 00000000..26937357 --- /dev/null +++ b/lib/jekyll/commands/migrate.rb @@ -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