Class: Texas::OptionParser
- Inherits:
-
Object
- Object
- Texas::OptionParser
- Defined in:
- lib/texas/option_parser.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ OptionParser
constructor
A new instance of OptionParser.
-
#parse ⇒ Object
Return a structure describing the options.
Constructor Details
#initialize(args) ⇒ OptionParser
Returns a new instance of OptionParser.
10 11 12 13 |
# File 'lib/texas/option_parser.rb', line 10 def initialize(args) @args = args = OpenStruct.new end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/texas/option_parser.rb', line 8 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/texas/option_parser.rb', line 8 def end |
Instance Method Details
#parse ⇒ Object
Return a structure describing the options.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/texas/option_parser.rb', line 18 def parse # The options specified on the command line will be collected in *options*. # We set default values here. .task = :build .work_dir = find_work_dir .check_mandatory_arguments = true .load_local_libs = true .contents_dir = Texas.contents_subdir_name .contents_template = find_contents_file("contents") .backtrace = false .colors = true .merge_config = nil .verbose = false .warnings = true .open_pdf = true lookup_and_execute_require_option(args) opts = ::OptionParser.new do |opts| opts. = "Usage: texas [options]" opts.separator "" opts.separator "Specific options:" opts.on("-d", "--dry-run", "Run without pdf generation") do |contents_template| .task = :dry end opts.on("-m", "--merge-config [CONFIG]", "Merge config with key from .texasrc") do |key| .merge_config = key end opts.on("-n", "--new [NAME]", "Create new texas project directory") do |name| .task = :new_project .check_mandatory_arguments = false .load_local_libs = false .new_project_name = name end opts.on("-r", "--require [LIBRARY]", "Require library before running texas") do |lib| # this block does nothing # require was already performed by lookup_and_execute_require_option # this option is here to ensure the -r switch is listed in the help option end opts.on("--watch", "Watch the given template") do |contents_template| .task = :watch .open_pdf = false end (opts) opts.separator "" opts.separator "Common options:" opts.on("--[no-]backtrace", "Switch backtrace") do |v| .backtrace = v end opts.on("-c", "--[no-]color", "Switch colors") do |v| .colors = v end opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| .verbose = v end opts.on("-w", "--[no-]warnings", "Switch warnings") do |v| .warnings = v end # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail("-h", "--help", "Show this message") do puts opts exit end # Another typical switch to print the version. opts.on_tail("--version", "Show version") do puts Texas::VERSION::STRING exit end end opts.parse!(args) unless args.empty? f = args.shift .contents_template = find_contents_file(f) .contents_dir = find_contents_dir(f) end if .check_mandatory_arguments check_mandatory! end end |