Class: Zypper::Onlinesearch::OptParseMain
- Inherits:
-
Object
- Object
- Zypper::Onlinesearch::OptParseMain
- Defined in:
- lib/zypper/onlinesearch/cli.rb
Overview
Parsing the input data.
Class Method Summary collapse
Class Method Details
.parse(args) ⇒ Object
13 14 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 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 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 |
# File 'lib/zypper/onlinesearch/cli.rb', line 13 def self.parse(args) = Struct.new(:operation, :query, :refresh, :engine, :timeout, :arch, :distributions, :types, :number, :view, :format).new .operation = :search .query = "" .refresh = false .engine = :all # :opensuse, :packman .timeout = 20 .arch = :compatible # :all .distributions = :compatible # :all .types = %i[supported community experimental unsupported] .number = 0 .view = :table .format = :all # or single format # options.preload = nil #used by :links or :page operations opt_parser = OptionParser.new do |opt| command = ENV["ZYPPER_ONLINESEARCH"] ? "zypper onlinesearch" : "onlinesearch" opt. = "Usage: #{command} [OPTIONS] [OPERATION]" opt.separator "" opt.separator "Operations:" opt.on("-s", "--search <STRING>", "Search for STRING to the online engines available") do |o| .operation = :search .query = o end opt.on("-p", "--page <PAGE_NAME>", "Get info about the PAGE_NAME") do |o| .operation = :page .query = o end opt.on("-l", "--links <PAGE_NAME>,<NTH>", Array, "Print all the links of the NTH item in the PAGE_NAME") do |o| .operation = :links .query = o[0] .number = o[1].to_i # options.preload = :page end opt.on("--clean-cache", "Clean the whole cache") do .operation = :cache_clean end opt.separator "" opt.separator "General Options" alt = Request::Search.constants.map(&:to_s).map(&:downcase).join(", ") opt.on("--engine <ENGINE>", "Use only ENGINE to search for (default: #{.engine}, alternatives: #{alt})") do |o| .engine = o.to_sym end opt.on("--refresh", "Refresh the cached values.") do .refresh = true end opt.on("--timeout <SECONDS>", "The SECONDS before an HTTP Timeout Error (Default: #{.timeout})") do |o| .timeout = o.to_f end opt.separator "" opt.separator "View options:" opt.on("--table", "Show the results as a table [DEFAULT]") do .view = :table end opt.on("--report", "Show the results as report") do .view = :report end opt.separator "" opt.separator '"Page" and "Links" options:' opt.on("--all-architectures", "Show all the available architectures") do .arch = :all end opt.on("--all-distributions", "Show all the available distributions") do .distributions = :all end opt.on("--no-supported", "Hide supported packages.") do .types.delete :supported end opt.on("--no-experimental", "Hide experimental packages.") do .types.delete :experimental end opt.on("--no-community", "Hide community packages.") do .types.delete :community end opt.on("--no-unsupported", "Hide unsupported packages.") do .types.delete :unsupported end opt.separator "" opt.separator '"Links" options:' opt.on("--format FORMAT", "Filter for packages with the specified FORMAT") do |o| .format = o.to_sym end opt.on("--architecture ARCHITECTURE", "Filter for packages with the specified ARCHITECTURE") do |o| .arch = o.to_sym end opt.on("--urls", "Show only the urls without headers") do .view = :urls end unless ENV["ZYPPER_ONLINESEARCH"] opt.separator "" opt.separator "Other:" opt.on_tail("-h", "--help", "Show this message") do puts opt exit end opt.on_tail("-v", "--version", "Show version") do puts VERSION exit end end end if ARGV.empty? puts opt_parser exit else opt_parser.parse!(args) end end |