Sha256: 28edd7443e97a4e09a57da4a0f68150a590cbfa68ad524475e93facdb84a6d86

Contents?: true

Size: 674 Bytes

Versions: 4

Compression:

Stored size: 674 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

4 entries across 4 versions & 1 rubygems

Version Path
my_scripts-0.0.13 lib/my_scripts/script.rb
my_scripts-0.0.12 lib/my_scripts/script.rb
my_scripts-0.0.11 lib/my_scripts/script.rb
my_scripts-0.0.9 lib/my_scripts/script.rb