Class: Thor
- Inherits:
-
Object
- Object
- Thor
- Defined in:
- lib/idcf/cli/gem_ext/thor/init_util.rb
Overview
Thor extention
Direct Known Subclasses
Class Method Summary collapse
- .command_help_string(command) ⇒ Object
-
.command_regist(command, require_path, arg) ⇒ Object
command regist.
-
.description ⇒ Object
command description.
- .error_exit(e) ⇒ Object
-
.exit_on_failure? ⇒ Boolean
Thor 0.19.4 ( github.com/erikhuda/thor/issues/244 ).
-
.init ⇒ Object
initialize settings.
-
.module_path ⇒ Object
module path.
-
.sub_command_regist(under_path, parent_dir_path = '', arg = {}) ⇒ Object
register sub command.
- .subcommand_structure ⇒ Object
Class Method Details
.command_help_string(command) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 58 def command_help_string(command) result = [command] map.each do |k, v| result << k if v.to_s == command.to_s end result.join('/') end |
.command_regist(command, require_path, arg) ⇒ Object
command regist
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 46 def command_regist(command, require_path, arg) require require_path class_const = require_path.classify.constantize class_const.init(arg) if arg.include?(command) || map.values.include?(command.to_sym) register class_const, command, "#{command_help_string(command)} [OPTION]", class_const.description end |
.description ⇒ Object
command description
20 21 22 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 20 def description raise Idcf::Cli::Error::CliError, 'Required Override' end |
.error_exit(e) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 88 def error_exit(e) STDERR.puts e. Idcf::Cli::Lib::Util::CliLogger.error(e.) Idcf::Cli::Lib::Util::CliLogger.cleaning() STDERR.puts "log path: #{Idcf::Cli::Lib::Util::CliLogger.current_path}" exit 1 end |
.exit_on_failure? ⇒ Boolean
Thor 0.19.4 ( github.com/erikhuda/thor/issues/244 )
8 9 10 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 8 def exit_on_failure? true end |
.init ⇒ Object
initialize settings
13 14 15 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 13 def init # When initialization is needed, override. end |
.module_path ⇒ Object
module path
69 70 71 72 73 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 69 def module_path class_names = to_s.underscore.split('/') class_names.pop class_names.join('/') end |
.sub_command_regist(under_path, parent_dir_path = '', arg = {}) ⇒ Object
register sub command
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 30 def sub_command_regist(under_path, parent_dir_path = '', arg = {}) b_path = Idcf::Cli::Lib::Util::Name.namespace(name).underscore Dir.glob(parent_dir_path + "/#{under_path}/*.rb").each do |f| file_name = File.basename(f, '.*') next if file_name == 'base' require_path = "#{b_path}/#{under_path}/#{file_name}" command_regist(file_name, require_path, arg) end end |
.subcommand_structure ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/idcf/cli/gem_ext/thor/init_util.rb', line 75 def subcommand_structure {}.tap do |result| commands.each_key do |k| result[k.to_s] = nil end result = subcommand_class_structure(result) map.each do |k, v| result[k.to_s] = result[v.to_s] unless result[v.to_s].nil? end end end |