Class: XMLTV::XmltvOptparser
- Inherits:
-
Object
- Object
- XMLTV::XmltvOptparser
- Defined in:
- lib/xmltv/xmltv.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/xmltv/xmltv.rb', line 107 def self.parse(args) = OpenStruct.new .basedir = "#{ENV['HOME']}/.xmltv" .validate = true xfound = nil %w{ xmllint tv_sort }.each do |prog| xfound = false ENV['PATH'].split(':').each do |path| xfound = true if test(?x, "#{path}/#{prog}") end break unless xfound end opts = OptionParser.new do |opts| opts. = "Usage: #{$PROGRAM_NAME} [options]" opts.separator "" opts.separator "Specific options:" opts.on("-a", "--list-all", "List all available channels") do |av| .available = av .action = true end opts.on("--add x,y,z", Array, "Add channels to config") do |list| .add = list .action = true end opts.on("--delete x,y,z", Array, "Delete channels from config") do |list| .del = list .action = true end opts.on("-l", "--list", "List configured channels") do |list| .list = list .action = true end opts.on("-c", "--config-file FILENAME", "Configuration file") do |list| .config = list end opts.on( "--basedir DIRNAME", "Basedir (#{.basedir})") do |list| .basedir = list end opts.on( "--no-validate", "Do not validate") do |v| .validate = false end opts.on( "--mailto USER", "Mail exception") do |user| .mailto = user end opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| .verbose = v end opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "Show this message") do STDERR.puts opts exit end opts.on_tail("--version", "Show version") do .version = true end end opts.parse!(args) if ! xfound && .validate .validate = false STDERR.puts "Disabled validation: xmllint and/or tv_sort not found" end end |