Sha256: 626dd902d54bde073c1ad04e02ab976eefac469c5159b3fc3d9b619a6850935a

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

module Birdwatcher
  module Commands
    class Resource < Birdwatcher::Command
      self.meta = {
        :description => "Execute commands from a resource file",
        :names       => %w(resource),
        :usage       => "resource FILE"
      }

      def self.detailed_usage
<<-USAGE
The #{'resource'.bold} command can be used to execute commands from a file on disk.
Resource files are simple text-based files containing one command per line. They
can be very convenient for common or repetitive workflows.

#{'USAGE:'.bold}

#{'Execute commands from a resource file:'.bold}
  resource <FILE>
USAGE
      end

      def run
        if !arguments?
          error("You must provide a path to a resource file")
          return false
        end
        filepath = File.expand_path(arguments.join(" "))
        if !File.exists?(filepath)
          error("File #{filepath.bold} does not exist")
          return false
        end
        if !File.readable?(filepath)
          error("File #{filepath} is not readable")
          return false
        end
        File.read(filepath).each_line do |command|
          command.strip!
          next if command.empty? || command.start_with?("#") || command.start_with?("//")
          console.handle_input(command.strip)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
birdwatcher-0.3.1 lib/birdwatcher/commands/resource.rb
birdwatcher-0.1.0 lib/birdwatcher/commands/resource.rb