Sha256: 048d15be80245cd53b4f8e93cda60f546eb02e0c18ccf1c2d352ce9ff284a106

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require "thor/shell/basic"

module GemSuit
  class CLI < Thor
    module Base
      module Shell

        def self.included(base)
          base.send :include, InstanceMethods
        end

        module InstanceMethods

          def shell
            @shell ||= Thor::Shell::Basic.new
          end

          def is?(*args)
            shell.send :is?, *args
          end

          def agree?(question, default = nil)
            opts   = %w(y n).collect{|x| !default.nil? && x =~ is?(default) ? x.upcase : x}
            answer = ask question, opts, default
            !!(answer =~ is?(:yes))
          end

          def ask(question, opts = nil, default = nil)
            in_brackets = [opts, default].compact.first
            statement   = [question, ("[#{in_brackets}]" unless in_brackets.nil?)].compact.join " "

            answer = shell.ask statement if options.interactive? || default.nil?
            answer.nil? || answer.empty? ? default.to_s : answer
          end

        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gem_suit-0.1.3 lib/gem_suit/cli/base/shell.rb
gem_suit-0.1.2 lib/gem_suit/cli/base/shell.rb
gem_suit-0.1.1 lib/gem_suit/cli/base/shell.rb
gem_suit-0.1.0 lib/gem_suit/cli/base/shell.rb