Class: Option
- Inherits:
-
Object
- Object
- Option
- Defined in:
- lib/rsokoban/option.rb
Overview
I parse the command line.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ Option
constructor
Here is a list of command line options : * –curses * –help * –help-output * –license * –portable * –tk * –version.
- #interface=(value) ⇒ Object
Constructor Details
#initialize ⇒ Option
TODO:
refactoring
Here is a list of command line options :
-
–curses
-
–help
-
–help-output
-
–license
-
–portable
-
–tk
-
–version
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rsokoban/option.rb', line 15 def initialize # Default option(s) @options = {:ui => :tk} optparse = OptionParser.new do|opts| opts. = "Usage: #{$0} [options]" # Options that define the UI opts.on( '-c', '--curses', 'Use curses console for user interface (default)' ) do @options[:ui] = :curses end opts.on( '-p', '--portable', 'Use standard console for user interface' ) do @options[:ui] = :portable end opts.on( '-t', '--tk', 'Make use of Tk library for a graphical user interface' ) do @options[:ui] = :tk end # Options that display a few information @options[:license] = false opts.on( '-l', '--license', 'Print program\'s license and exit' ) do @options[:license] = true end @options[:version] = false opts.on( '-v', '--version', 'Print version number and exit' ) do @options[:version] = true end # Options that display some help @options[:help_output] = false opts.on( '-o', '--help-output', 'Print help on output options and exit' ) do @options[:help_output] = true end opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end begin optparse.parse! rescue OptionParser::InvalidOption => e puts e.to_s exit 1 end print_version if @options[:version] print_license if @options[:license] print_help_output if @options[:help_output] end |
Instance Method Details
#[](key) ⇒ Object
70 71 72 |
# File 'lib/rsokoban/option.rb', line 70 def [](key) @options[key] end |
#interface=(value) ⇒ Object
74 75 76 |
# File 'lib/rsokoban/option.rb', line 74 def interface=(value) @options[:ui] = value end |