Class: Gem::Release::GemCommand::Setup

Inherits:
Struct
  • Object
show all
Defined in:
lib/gem/release/support/gem_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd



6
7
8
# File 'lib/gem/release/support/gem_command.rb', line 6

def cmd
  @cmd
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/gem/release/support/gem_command.rb', line 6

def name
  @name
end

Instance Method Details

#argumentsObject



34
35
36
37
38
# File 'lib/gem/release/support/gem_command.rb', line 34

def arguments
  arg  = const.args.map(&:first).max_by(&:size)
  args = const.args.map { |name, summary| [name.to_s.ljust(arg.size), summary] }
  args.map { |pair| pair.join(' - ') }.join("\n")
end

#constObject



25
26
27
# File 'lib/gem/release/support/gem_command.rb', line 25

def const
  Cmds[name] || raise("Unknown command #{name}")
end

#optsObject



21
22
23
# File 'lib/gem/release/support/gem_command.rb', line 21

def opts
  const.opts + Cmds::Base.opts
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gem/release/support/gem_command.rb', line 7

def run
  cmd.summary      = const.summary
  cmd.description  = const.description
  cmd.usage        = usage
  cmd.arguments    = arguments
  cmd.defaults_str = ''

  opts.each do |args|
    cmd.add_option(*args.first) do |*a|
      cmd.instance_exec(*a, &args.last)
    end
  end
end

#usageObject



29
30
31
32
# File 'lib/gem/release/support/gem_command.rb', line 29

def usage
  args = const.args.map(&:first)
  [:gem, name, args.map { |arg| "[#{arg}]" }.join(' ')].join(' ')
end