Class: RightScriptSync::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/rightscript_sync/command_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandLine

Returns a new instance of CommandLine.



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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rightscript_sync/command_line.rb', line 27

def initialize
  @options = {}
  begin
    @optparse = OptionParser.new do |opts|
      opts.banner = "Usage: #{$0} options"
      
      @options[:dry_run] = false
      opts.on( '--dry-run', 'Output the parsed files to STDOUT' ) do
        @options[:dry_run] = true
      end
      
      opts.on( '--output-path DIR', 'Use DIR as output directory') do |dir|
        @options[:output_path] = dir.gsub(/\/+$/, '')
      end
      
      opts.on( '--account-id ID', 'RightScale Account ID' ) do||
        @options[:account_id] = 
      end

      opts.on( '--username USERNAME', 'RightScale Username' ) do|username|
        @options[:username] = username
      end

      opts.on( '--password PASSWORD', 'RightScale Password' ) do|password|
        @options[:password] = password
      end

      @options[:log_level] = Logger::INFO
      opts.on( '--log-level LEVEL', 'Logging level' ) do|level|
        @options[:log_level] = Logger.const_get level.upcase
      end


      opts.on( '-V', '--version', 'Display version information' ) do
        puts "RightScript Sync #{RightScriptSync::VERSION}"
        puts "Copyright (C) 2012 Erik Osterman <[email protected]>"
        puts "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
        puts "This is free software: you are free to change and redistribute it."
        puts "There is NO WARRANTY, to the extent permitted by law."
        exit
      end

      opts.on( '-h', '--help', 'Display this screen' ) do
        puts opts
        exit
      end
    end

    @optparse.parse!

    raise MissingArgumentException.new("Missing --account-id argument") if @options[:account_id].nil?
    raise MissingArgumentException.new("Missing --username argument") if @options[:username].nil?
    raise MissingArgumentException.new("Missing --password argument") if @options[:password].nil?
    raise MissingArgumentException.new("Missing --output-path argument") if @options[:output_path].nil?

    @downloader = Downloader.new(@options)
  rescue MissingArgumentException => e
    puts e.message
    puts @optparse
    exit (1)
  end
end

Instance Attribute Details

#downloaderObject

Returns the value of attribute downloader.



26
27
28
# File 'lib/rightscript_sync/command_line.rb', line 26

def downloader
  @downloader
end

Instance Method Details

#executeObject



90
91
92
# File 'lib/rightscript_sync/command_line.rb', line 90

def execute
  @downloader.execute
end