Sha256: 84b7534dfc8358065dc11d0cd5ad608de46a41e4c38c6676f060a712519c8bce

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

module MyScripts
  # Base class for all scripts. Subclass it and override run method with actual
  # work your script will be doing
  class Script
    def initialize( name, argv, cli )
      @name = name
      @argv = argv
      @cli = cli
    end

    def run
    end

    def puts *args
      @cli.stdout.puts *args
    end

    def usage examples, explanation = nil
      puts "Usage:"
      puts (examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| "    #{@name} #{line}"}
      puts explanation if explanation
      exit 1
    end

    def to_s
      "#{@name} #{@argv.join(' ')} -> #{self.class}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
my_scripts-0.0.17 lib/my_scripts/script.rb