Class: ThreddedCreateApp::CLI::Flags

Inherits:
Object
  • Object
show all
Defined in:
lib/thredded_create_app/cli.rb

Overview

rubocop:enable Metrics/AbcSize,Metrics/BlockLength,Metrics/MethodLength

Instance Method Summary collapse

Constructor Details

#initialize(op, options) ⇒ Flags



139
140
141
142
# File 'lib/thredded_create_app/cli.rb', line 139

def initialize(op, options)
  @op      = op
  @options = options
end

Instance Method Details

#bool(as, short = nil, long, desc) ⇒ Object

rubocop:disable Style/OptionalArguments



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/thredded_create_app/cli.rb', line 145

def bool(as, short = nil, long, desc)
  flag_args = [short, long].compact
  if long.start_with?('--[no-]')
    desc += " (default: #{DEFAULTS[as]})" if DEFAULTS[as]
    @op.on(*flag_args, desc) do |v|
      @options[as] = v
      yield v if block_given?
    end
  else
    @op.on(*flag_args, desc) do
      @options[as] = !long.start_with?('--no-')
      yield @options[as] if block_given?
    end
  end
end