Class: Bun::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/bun/arguments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Arguments

Returns a new instance of Arguments.



5
6
7
# File 'lib/bun/arguments.rb', line 5

def initialize(arguments)
  @arguments = arguments
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



9
10
11
# File 'lib/bun/arguments.rb', line 9

def group
  @group
end

#optimisticObject Also known as: optimistic?

Returns the value of attribute optimistic.



9
10
11
# File 'lib/bun/arguments.rb', line 9

def optimistic
  @optimistic
end

Returns the value of attribute print.



9
10
11
# File 'lib/bun/arguments.rb', line 9

def print
  @print
end

#skip_installObject Also known as: skip_install?

Returns the value of attribute skip_install.



9
10
11
# File 'lib/bun/arguments.rb', line 9

def skip_install
  @skip_install
end

#strictObject Also known as: strict?

Returns the value of attribute strict.



9
10
11
# File 'lib/bun/arguments.rb', line 9

def strict
  @strict
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/bun/arguments.rb', line 16

def empty?
  @arguments.empty?
end

#parseObject



20
21
22
23
24
25
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
# File 'lib/bun/arguments.rb', line 20

def parse
  opt_parser = OptionParser.new do |opts|
    opts.banner = Bun::Messages::USAGE

    opts.on("-P", "--print", "# Just print the gem name and version and exit.") do
      self.print = true
    end

    opts.on("-o", "--optimistic", "# Use optimistic version range >= instead of ~>.") do
      self.optimistic = true
    end

    opts.on("-S", "--strict", "# Use strict version instead of ~> range.") do
      self.strict = true
    end

    opts.on("-d", "--development", "# Add gem to development group.") do
      self.group = :development
    end

    opts.on("-t", "--test", "# Add gem to test group.") do
      self.group = :test
    end

    opts.on("-s", "--skip-install", "# Skip the install step.") do
      self.skip_install = true
    end

    opts.on_tail("-h", "--help", "# Print these usage instructions.") do
      puts opts
    end

    opts.on("-v", "--version", "# Show current Bun version.") do
      puts Bun::VERSION
    end
  end

  begin
    opt_parser.parse(arguments)
  rescue OptionParser::InvalidOption
    puts opt_parser
  end
end