Class: Command::CommandBase
- Inherits:
-
Object
- Object
- Command::CommandBase
- Defined in:
- lib/commandbase.rb
Direct Known Subclasses
Alias, Browser, Convert, Diff, Download, Flag, Folder, Freeze, Help, Init, Inspect, List, Mail, Remove, Send, Setting, Update, Version
Class Method Summary collapse
-
.execute!(argv) ⇒ Object
普通にコマンドを実行するけど、exit(2) を補足してexitstatus を返す 正常終了なら0.
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize(postfix = "") ⇒ CommandBase
constructor
A new instance of CommandBase.
- #load_local_settings ⇒ Object
- #oneline_help(msg) ⇒ Object
Constructor Details
#initialize(postfix = "") ⇒ CommandBase
Returns a new instance of CommandBase.
10 11 12 13 14 15 16 |
# File 'lib/commandbase.rb', line 10 def initialize(postfix = "") @opt = OptionParser.new(nil, 20) @opt. = ("<bold><green>" + TermColor.escape("Usage: narou #{self.class.to_s.scan(/::(.+)$/)[0][0].downcase} #{postfix}") + "</green></bold>").termcolor @options = {} end |
Class Method Details
.execute!(argv) ⇒ Object
普通にコマンドを実行するけど、exit(2) を補足してexitstatus を返す 正常終了なら0
42 43 44 45 46 47 48 |
# File 'lib/commandbase.rb', line 42 def self.execute!(argv) self.new.execute(argv) rescue SystemExit => e e.status else 0 end |
Instance Method Details
#execute(argv) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/commandbase.rb', line 18 def execute(argv) @opt.parse!(argv) rescue OptionParser::InvalidOption => e error "不正なオプションです(#{e})" exit 1 rescue OptionParser::MissingArgument => e error "オプションの引数が不正です(#{e})" exit 1 end |
#load_local_settings ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/commandbase.rb', line 28 def load_local_settings command_prefix = self.class.to_s.scan(/[^:]+$/)[0].downcase local_settings = LocalSetting.get["local_setting"] local_settings.each do |name, value| if name =~ /^#{command_prefix}\.(.+)$/ @options[$1] = value end end end |
#oneline_help(msg) ⇒ Object
50 51 52 |
# File 'lib/commandbase.rb', line 50 def oneline_help(msg) "" end |