Class: CommandLineScript

Inherits:
CommandLine show all
Includes:
Assertions, Constants, Examples
Defined in:
app/models/command_line.rb

Overview

CommandLine

Defined Under Namespace

Modules: Assertions, Constants, Examples

Constant Summary

Constants included from Examples

Examples::SELF

Instance Method Summary collapse

Methods included from Assertions

#assert_post_conditions, #assert_pre_conditions

Methods inherited from CommandLine

#initialize, #ruby_mime

Methods included from CommandLine::ClassMethods

#path_of_command

Methods included from CommandLine::Assertions

#assert_post_conditions, #assert_pre_conditions

Constructor Details

This class inherits a constructor from CommandLine

Instance Method Details

#add_option(name, description = name, long_option = name, short_option = name[0]) ⇒ Object


73
74
75
76
# File 'app/models/command_line.rb', line 73

def add_option(name, description=name, long_option=name, short_option=name[0])
	option=CommandLineOption.new(name, description, long_option, short_option)
	@options = (@options.nil? ? [] : @options)+[option]
end

#parse_optionsObject

add_option


77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/command_line.rb', line 77

def parse_options
	@commands = []
	OptionParser.new do |opts|
		opts.banner = "Usage: #@basename} --<command> files"
		@options.each do |option|
			opts.on(option.short_option, "--[no-]#{option.long_option}", option.description) do |o|
				@commands+=[option.name] if o
		  end #on
	  end #each
	end.parse!
end

#runObject

parse_options


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/command_line.rb', line 88

def run
	case ARGV.size
	when 0 then # scite testing defaults command and file
		puts "work_flow --<command> <file>"
		this_file=File.expand_path(__FILE__)
		argv=[this_file] # incestuous default test case for scite
	else
		argv=ARGV
	end #case
	if @coomands.size=0 then
		@commands=[:test]
	end #if
	argv.each do |f|
		command_line=CommandLine.new(f)
		@commands.each do |c|
			command_line.method(c)
		end #each
	end #each
end