Sha256: 18d7669413f6bfd3d2b4550ef1bc33995cc2ecac20e98c1d1679cd28cd890acb

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

require 'optparse'
 
module Saga
  class Runner
    def initialize(argv)
      @argv = argv
      @options = {}
    end
    
    def parser
      OptionParser.new do |opts|
        opts.banner =  "Usage: saga [command] [options] <file>"
        opts.separator ""
        opts.on("-h", "--help", "Show help") do
          puts opts
          exit
        end
      end
    end
    
    def run_command(command, options)
      case command
      when :run
      else
        filename = File.expand_path(command)
        document = Saga::Parser.parse(File.read(filename))
        puts Saga::Formatter.format(document)
      end
    end
    
    def run
      argv = @argv.dup
      parser.parse!(argv)
      if command = argv.shift
        run_command(command, @options)
      else
        puts parser.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saga-0.1.0 lib/saga/runner.rb