Sha256: c064c7af25158ea3382a70fafb3588256b8ec452027ac7ebf01b7eaded820cd1
Contents?: true
Size: 993 Bytes
Versions: 7
Compression:
Stored size: 993 Bytes
Contents
# -*- coding: UTF-8 -*- # # Copyright 2013 whiteleaf. All rights reserved. # require "optparse" module Command class CommandBase def initialize(postfix = "") @opt = OptionParser.new(nil, 20) @opt.banner = "Usage: #{@opt.program_name} #{self.class.to_s.scan(/::(.+)$/)[0][0].downcase} #{postfix}" @options = {} end def execute(argv) @opt.parse!(argv) rescue OptionParser::InvalidOption => e warn "不正なオプションです(#{e})" exit 1 rescue OptionParser::MissingArgument => e warn "オプションの引数が不正です(#{e})" exit 1 end # # 普通にコマンドを実行するけど、exit(2) を補足してexitstatus を返す # 正常終了なら0 # def self.execute_and_rescue_exit(argv) self.new.execute(argv) rescue SystemExit => e e.status else 0 end def oneline_help(msg) "" end end end
Version data entries
7 entries across 7 versions & 1 rubygems