Skip to content

Instantly share code, notes, and snippets.

@tbrooke
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbrooke/b155e6c5530718864319 to your computer and use it in GitHub Desktop.
Save tbrooke/b155e6c5530718864319 to your computer and use it in GitHub Desktop.
Simple Command Line Parser in Ruby
## Gemfile Mainly for Specs
gem 'rspec', github: 'rspec/rspec'
gem 'rspec-core', github: 'rspec/rspec-core'
gem 'rspec-mocks', github: 'rspec/rspec-mocks'
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
gem 'rspec-support', github: 'rspec/rspec-support'
#!~/school/env ruby
## Simple Parser read in a file from the command line and spit it back out like cat
## Loosely based on Gregory Brown's article on Command line Utilities
class Reader
## This reads in the file on the Command line
def Initialize(arg)
@params, @args = parse_options(argv)
@display = Par::Display.new(@params)
end
def run
if @files.empty?
@display.render(STDIN)
else
@files.each do |filename|
File.open(filename) { |f| @display.render(f) }
end
end
end
def parse_options(argv)
# ignore this for now
end
end
class Parser
# This is simple parsing of the file
end
### Spec file for Parse
require 'rspec'
require 'parse'
describe Parse do
it 'reads a file as input from the comand line' do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment