Sha256: 55950192666a61f0a189435f2b0e533808f73ba2ba34e05c1e70f6e29ea81a9b

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

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 = ("<bold><green>" +
                     TermColor.escape("Usage: narou #{self.class.to_s.scan(/::(.+)$/)[0][0].downcase} #{postfix}") +
                     "</green></bold>").termcolor
      @options = {}
    end

    def execute(argv)
      @opt.parse!(argv)
    rescue OptionParser::InvalidOption => e
      error "不正なオプションです(#{e})"
      exit 1
    rescue OptionParser::MissingArgument => e
      error "オプションの引数が不正です(#{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

29 entries across 29 versions & 1 rubygems

Version Path
narou-1.4.4 lib/commandbase.rb
narou-1.4.3 lib/commandbase.rb
narou-1.4.2.rc2 lib/commandbase.rb
narou-1.4.2.rc1 lib/commandbase.rb
narou-1.4.1.1 lib/commandbase.rb
narou-1.4.1 lib/commandbase.rb
narou-1.4.0 lib/commandbase.rb
narou-1.3.5.1 lib/commandbase.rb
narou-1.3.5 lib/commandbase.rb
narou-1.3.4 lib/commandbase.rb
narou-1.3.3 lib/commandbase.rb
narou-1.3.2 lib/commandbase.rb
narou-1.3.1 lib/commandbase.rb
narou-1.3.0.1 lib/commandbase.rb
narou-1.3.0 lib/commandbase.rb
narou-1.2.9 lib/commandbase.rb
narou-1.2.9.rc1 lib/commandbase.rb
narou-1.2.8 lib/commandbase.rb
narou-1.2.7 lib/commandbase.rb
narou-1.2.6 lib/commandbase.rb