Class: GDocsMigration::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/gdocs-migration/cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gdocs-migration/cli.rb', line 26

def self.execute(stdout, arguments=[])

  # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.

  options = {
    :from     => nil,
    :to       => nil
  }
  mandatory_options = %w(from to)

  parser = OptionParser.new do |opts|
    opts.banner = "      GDocsMigration (http://github.com/chdorner/gdocs-migration)\n\n      Usage: \#{File.basename($0)} [options]\n\n      Options are:\n    BANNER\n    opts.separator \"\"\n    opts.on(\"-f\", \"--from=FROM\", String,\n            \"The Google account to use as source.\") { |arg| options[:from] = arg }\n    opts.on(\"-t\", \"--to=TO\", String,\n            \"The Google account to use as destination.\") { |arg| options[:to] = arg }\n    opts.on(\"-h\", \"--help\",\n            \"Show this help message.\") { stdout.puts opts; exit }\n    opts.parse!(arguments)\n    \n    if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }\n      stdout.puts opts; exit\n    end\n  end\n\n  from = options[:from]\n  to = options[:to]\n\n  migration = GDocsMigration::Migration.new from, to\n  migration.migrate\nend\n".gsub(/^          /,'')