Class: Benry::CmdApp::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/benry/cmdapp.rb

Constant Summary collapse

FORMAT_OPTION =
"  %-18s : %s"
FORMAT_ACTION =
"  %-18s : %s"
FORMAT_ABBREV =
"  %-10s =>  %s"
FORMAT_USAGE =
"  $ %s"
FORMAT_CATEGORY =

same as ‘config.format_action’ if nil

nil
DECORATION_COMMAND =

bold

"\e[1m%s\e[0m"
DECORATION_HEADER =

bold, blue

"\e[1;34m%s\e[0m"
DECORATION_EXTRA =

gray color

"\e[2m%s\e[0m"
DECORATION_STRONG =

bold

"\e[1m%s\e[0m"
DECORATION_WEAK =

gray color

"\e[2m%s\e[0m"
DECORATION_HIDDEN =

gray color

"\e[2m%s\e[0m"
DECORATION_DEBUG =

gray color

"\e[2m%s\e[0m"
DECORATION_ERROR =

red color

"\e[31m%s\e[0m"
APP_USAGE =
"<action> [<arguments>...]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_desc, app_version = nil, app_name: nil, app_command: nil, app_usage: nil, app_detail: nil, default_action: nil, help_description: nil, help_postamble: nil, format_option: nil, format_action: nil, format_abbrev: nil, format_usage: nil, format_category: nil, deco_command: nil, deco_header: nil, deco_extra: nil, deco_strong: nil, deco_weak: nil, deco_hidden: nil, deco_debug: nil, deco_error: nil, option_help: true, option_version: nil, option_list: true, option_topic: :hidden, option_all: true, option_verbose: false, option_quiet: false, option_color: false, option_debug: :hidden, option_trace: false, option_dryrun: false, backtrace_ignore_rexp: nil) ⇒ Config

Returns a new instance of Config.



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# File 'lib/benry/cmdapp.rb', line 1168

def initialize(app_desc, app_version=nil,
               app_name: nil, app_command: nil, app_usage: nil, app_detail: nil,
               default_action: nil,
               help_description: nil, help_postamble: nil,
               format_option: nil, format_action: nil, format_abbrev: nil, format_usage: nil, format_category: nil,
               deco_command: nil, deco_header: nil, deco_extra: nil,
               deco_strong: nil, deco_weak: nil, deco_hidden: nil, deco_debug: nil, deco_error: nil,
               option_help: true, option_version: nil, option_list: true, option_topic: :hidden, option_all: true,
               option_verbose: false, option_quiet: false, option_color: false,
               option_debug: :hidden, option_trace: false, option_dryrun: false,
               backtrace_ignore_rexp: nil)
  #; [!pzp34] if `option_version` is not specified, then set true if `app_version` is provided.
  option_version = !! app_version if option_version == nil
  #
  @app_desc           = app_desc
  @app_version        = app_version
  @app_name           = app_name
  @app_command        = app_command || File.basename($0)
  @app_usage          = app_usage
  @app_detail         = app_detail
  @default_action     = default_action
  @help_description   = help_description
  @help_postamble     = help_postamble
  @format_option      = format_option || FORMAT_OPTION
  @format_action      = format_action || FORMAT_ACTION
  @format_abbrev      = format_abbrev || FORMAT_ABBREV
  @format_usage       = format_usage  || FORMAT_USAGE
  @format_category    = format_category   # nil means to use @format_action
  @deco_command       = deco_command || DECORATION_COMMAND  # for command name in help
  @deco_header        = deco_header  || DECORATION_HEADER   # for "Usage:" or "Actions"
  @deco_extra         = deco_extra   || DECORATION_EXTRA    # for "(default: )" or "(depth=1)"
  @deco_strong        = deco_strong  || DECORATION_STRONG   # for `important: true`
  @deco_weak          = deco_weak    || DECORATION_WEAK     # for `important: false`
  @deco_hidden        = deco_hidden  || DECORATION_HIDDEN   # for `hidden: true`
  @deco_debug         = deco_error   || DECORATION_DEBUG
  @deco_error         = deco_error   || DECORATION_ERROR
  @option_help        = option_help         # enable or disable `-h, --help`
  @option_version     = option_version      # enable or disable `-V, --version`
  @option_list        = option_list         # enable or disable `-l, --list`
  @option_topic       = option_topic        # enable or disable `-L <topic>`
  @option_all         = option_all          # enable or disable `-a, --all`
  @option_verbose     = option_verbose      # enable or disable `-v, --verbose`
  @option_quiet       = option_quiet        # enable or disable `-q, --quiet`
  @option_color       = option_color        # enable or disable `--color[=<on|off>]`
  @option_debug       = option_debug        # enable or disable `--debug`
  @option_trace       = option_trace        # enable or disable `-T, --trace`
  @option_dryrun      = option_dryrun       # enable or disable `-X, --dryrun`
  @backtrace_ignore_rexp = backtrace_ignore_rexp
  #
  #@verobse_mode       = nil
  #@quiet_mode         = nil
  #@color_mode         = nil
  #@debug_mode         = nil
  @trace_mode         = nil
end

Instance Attribute Details

#app_commandObject

Returns the value of attribute app_command.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_command
  @app_command
end

#app_descObject

Returns the value of attribute app_desc.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_desc
  @app_desc
end

#app_detailObject

Returns the value of attribute app_detail.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_detail
  @app_detail
end

#app_nameObject

Returns the value of attribute app_name.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_name
  @app_name
end

#app_usageObject

Returns the value of attribute app_usage.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_usage
  @app_usage
end

#app_versionObject

Returns the value of attribute app_version.



1224
1225
1226
# File 'lib/benry/cmdapp.rb', line 1224

def app_version
  @app_version
end

#backtrace_ignore_rexpObject

Returns the value of attribute backtrace_ignore_rexp.



1234
1235
1236
# File 'lib/benry/cmdapp.rb', line 1234

def backtrace_ignore_rexp
  @backtrace_ignore_rexp
end

#deco_commandObject

Returns the value of attribute deco_command.



1227
1228
1229
# File 'lib/benry/cmdapp.rb', line 1227

def deco_command
  @deco_command
end

#deco_debugObject

Returns the value of attribute deco_debug.



1229
1230
1231
# File 'lib/benry/cmdapp.rb', line 1229

def deco_debug
  @deco_debug
end

#deco_errorObject

Returns the value of attribute deco_error.



1229
1230
1231
# File 'lib/benry/cmdapp.rb', line 1229

def deco_error
  @deco_error
end

#deco_extraObject

Returns the value of attribute deco_extra.



1227
1228
1229
# File 'lib/benry/cmdapp.rb', line 1227

def deco_extra
  @deco_extra
end

#deco_headerObject

Returns the value of attribute deco_header.



1227
1228
1229
# File 'lib/benry/cmdapp.rb', line 1227

def deco_header
  @deco_header
end

#deco_hiddenObject

Returns the value of attribute deco_hidden.



1229
1230
1231
# File 'lib/benry/cmdapp.rb', line 1229

def deco_hidden
  @deco_hidden
end

#deco_strongObject

Returns the value of attribute deco_strong.



1229
1230
1231
# File 'lib/benry/cmdapp.rb', line 1229

def deco_strong
  @deco_strong
end

#deco_weakObject

Returns the value of attribute deco_weak.



1229
1230
1231
# File 'lib/benry/cmdapp.rb', line 1229

def deco_weak
  @deco_weak
end

#default_actionObject

Returns the value of attribute default_action.



1225
1226
1227
# File 'lib/benry/cmdapp.rb', line 1225

def default_action
  @default_action
end

#format_abbrevObject

Returns the value of attribute format_abbrev.



1226
1227
1228
# File 'lib/benry/cmdapp.rb', line 1226

def format_abbrev
  @format_abbrev
end

#format_actionObject

Returns the value of attribute format_action.



1226
1227
1228
# File 'lib/benry/cmdapp.rb', line 1226

def format_action
  @format_action
end

#format_categoryObject

Returns the value of attribute format_category.



1226
1227
1228
# File 'lib/benry/cmdapp.rb', line 1226

def format_category
  @format_category
end

#format_optionObject

Returns the value of attribute format_option.



1226
1227
1228
# File 'lib/benry/cmdapp.rb', line 1226

def format_option
  @format_option
end

#format_usageObject

Returns the value of attribute format_usage.



1226
1227
1228
# File 'lib/benry/cmdapp.rb', line 1226

def format_usage
  @format_usage
end

#help_descriptionObject

Returns the value of attribute help_description.



1228
1229
1230
# File 'lib/benry/cmdapp.rb', line 1228

def help_description
  @help_description
end

#help_postambleObject

Returns the value of attribute help_postamble.



1228
1229
1230
# File 'lib/benry/cmdapp.rb', line 1228

def help_postamble
  @help_postamble
end

#option_allObject

Returns the value of attribute option_all.



1230
1231
1232
# File 'lib/benry/cmdapp.rb', line 1230

def option_all
  @option_all
end

#option_colorObject

Returns the value of attribute option_color.



1231
1232
1233
# File 'lib/benry/cmdapp.rb', line 1231

def option_color
  @option_color
end

#option_debugObject

Returns the value of attribute option_debug.



1232
1233
1234
# File 'lib/benry/cmdapp.rb', line 1232

def option_debug
  @option_debug
end

#option_dryrunObject

Returns the value of attribute option_dryrun.



1232
1233
1234
# File 'lib/benry/cmdapp.rb', line 1232

def option_dryrun
  @option_dryrun
end

#option_helpObject

Returns the value of attribute option_help.



1230
1231
1232
# File 'lib/benry/cmdapp.rb', line 1230

def option_help
  @option_help
end

#option_listObject

Returns the value of attribute option_list.



1230
1231
1232
# File 'lib/benry/cmdapp.rb', line 1230

def option_list
  @option_list
end

#option_quietObject

Returns the value of attribute option_quiet.



1231
1232
1233
# File 'lib/benry/cmdapp.rb', line 1231

def option_quiet
  @option_quiet
end

#option_topicObject

Returns the value of attribute option_topic.



1230
1231
1232
# File 'lib/benry/cmdapp.rb', line 1230

def option_topic
  @option_topic
end

#option_traceObject

Returns the value of attribute option_trace.



1232
1233
1234
# File 'lib/benry/cmdapp.rb', line 1232

def option_trace
  @option_trace
end

#option_verboseObject

Returns the value of attribute option_verbose.



1231
1232
1233
# File 'lib/benry/cmdapp.rb', line 1231

def option_verbose
  @option_verbose
end

#option_versionObject

Returns the value of attribute option_version.



1230
1231
1232
# File 'lib/benry/cmdapp.rb', line 1230

def option_version
  @option_version
end

#trace_modeObject Also known as: trace_mode?

, :verbose_mode, :quiet_mode, :color_mode, :debug_mode



1233
1234
1235
# File 'lib/benry/cmdapp.rb', line 1233

def trace_mode
  @trace_mode
end

Instance Method Details

#each(sort: false, &b) ⇒ Object



1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
# File 'lib/benry/cmdapp.rb', line 1237

def each(sort: false, &b)
  #; [!yxi7r] returns Enumerator object if block not given.
  return enum_for(:each, sort: sort) unless block_given?()
  #; [!64zkf] yields each config name and value.
  #; [!0zatj] sorts key names if `sort: true` passed.
  ivars = instance_variables()
  ivars = ivars.sort() if sort
  ivars.each do |ivar|
    val = instance_variable_get(ivar)
    yield ivar.to_s[1..-1].intern, val
  end
  nil
end