Last active
August 29, 2015 14:04
-
-
Save tbrooke/b155e6c5530718864319 to your computer and use it in GitHub Desktop.
Simple Command Line Parser in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!~/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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