Class: Slackware::Args
- Inherits:
-
Object
- Object
- Slackware::Args
- Defined in:
- lib/slackware/args.rb
Overview
Args is the unified arguement parser for the slack-utils utilities.
Class Method Summary collapse
Class Method Details
.parse(args, flags = nil, banner = nil) ⇒ Object
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 |
# File 'lib/slackware/args.rb', line 28 def self.parse(args,flags = nil, = nil) flags = [] unless flags.is_a?(Array) = {} opts = OptionParser.new do |opts| if opts. = end if flags.include?(:color) opts.on("-c", "--color", "Colorize output") do |o| [:color] = o end end if flags.include?(:epoch) opts.on("-e", "--epoch", "Print the time stamp in seconds since 1970-01-01 00:00:00 UTC ") do |o| [:epoch] = o end end if flags.include?(:pkg_name) opts.on("-p", "--pkg [NAME]", "Package PKGNAME (loose match)") do |o| [:pkg] = o end end if flags.include?(:pkg_version) opts.on("-V", "--Version [VERSION]", "Package VERSION (loose match)") do |o| [:version] = o end end if flags.include?(:pkg_arch) opts.on("-a", "--arch [ARCH]", "Package ARCH (exact match)") do |o| [:arch] = o end end if flags.include?(:pkg_build) opts.on("-b", "--build [BUILD]", "Package BUILD (exact match)") do |o| [:build] = o end end if flags.include?(:pkg_tag) opts.on("-t", "--tag [TAG]", "Package TAG (loose match)") do |o| [:tag] = o end end if flags.include?(:case_insensitive) opts.on("-i", "When searching, do a case insensitive match") do |o| [:case_insensitive] = o end end if flags.include?(:force_all) opts.on("-f", "--force", "force me to show all files") do |o| [:force] = o end end if flags.include?(:debug) opts.on("-D", "--debug", "show debugging output") do |o| [:debug] = o end end opts.on("-v", "--version", "Display version of this software") do |o| printf("slack-utils version: %s, Slackware version: %s\n", Slackware::UTILS_VERSION, Slackware::System.version ) exit(0) end end begin opts.parse! return rescue OptionParser::InvalidOption => ex $stderr.write("ERROR: #{e.}, see --help\n") exit(1) end end |