Class: RubyClone::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_clone/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Options

Returns a new instance of Options.



9
10
11
12
13
# File 'lib/ruby_clone/options.rb', line 9

def initialize(output)
  @output = output
  @configurations = {}
  @configurations[:backup_file] = '~/.ruby_clone'
end

Instance Attribute Details

#configurationsObject (readonly)

Returns the value of attribute configurations.



6
7
8
# File 'lib/ruby_clone/options.rb', line 6

def configurations
  @configurations
end

#profileObject (readonly)

Returns the value of attribute profile.



7
8
9
# File 'lib/ruby_clone/options.rb', line 7

def profile
  @profile
end

Instance Method Details

#parse(argv) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_clone/options.rb', line 15

def parse(argv)
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: ruby_clone [options] profile"

    opts.on("-b", "--backup-file path", String, "Change the path to backup file (default is #{ENV['HOME']}/.ruby_clone)") do |backup_file|
      @configurations[:backup_file] = backup_file
    end

    opts.on("-d", "--dry-run", "Show what would have been transferred") do
      @configurations[:dry_run] = true
    end

    opts.on("-h", "--help", "This message") do
      @output.puts opts
    end

    argv = %w[-h] if argv.empty?
    opts.parse!(argv)
  end
  opts
end