Sha256: 4e302d681e0528f4e9d11e4b3efea6357aad30ca3be38ce3dbbd29ca74e93c3a

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module Wordless
  module CLIHelper
    extend ActiveSupport::Concern

    included do
      [ :say, :run ].each do |sym|
        define_method sym do |*args|
          thor.send(sym, *args)
        end
        private sym
      end
    end

    private

    def thor
      raise NotImplementedError, "Including class must provide a thor instance object"
    end

    def info(message)
      log_message message
    end

    def error(message)
      log_message message, :red
      exit
    end

    def success(message)
      log_message message, :green
    end

    def warning(message)
      log_message message, :yellow
    end

    def ensure_wp_cli_installed!
      error("Cannot continue: WP-CLI is not installed.") unless wp_cli_installed?
    end

    def run_command(command)
      system("#{command} >>#{void} 2>&1")
    end

    def wp_cli_installed?
      run_command("which wp")
    end

    def log_message(message, color = nil)
      say message, color
    end

    def void
      RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wordless-1.1.6 lib/wordless/cli_helper.rb
wordless-1.1.5 lib/wordless/cli_helper.rb
wordless-1.1.2 lib/wordless/cli_helper.rb
wordless-1.1.1 lib/wordless/cli_helper.rb
wordless-1.1.0 lib/wordless/cli_helper.rb