| 1 | package urpm::args; | ||
| 2 | |||
| 3 | |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | no warnings 'once'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Getopt::Long; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 0 | ▶ | use urpm::download; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use urpm::msg; | ||
| 10 | use urpm::util 'file2absolute_file'; | ||
| 11 | use Exporter; | ||
| 12 | |||
| 13 | our @ISA = 'Exporter'; | ||
| 14 | our @EXPORT = '%options'; | ||
| 15 | |||
| 16 | # The program that invokes us | ||
| 17 | (my $tool = $0) =~ s!.*/!!; | ||
| 18 | |||
| 19 | # Configuration of Getopt. urpmf is a special case, because we need to | ||
| 20 | # parse non-alphanumerical options (-! -( -)) | ||
| 21 | my @configuration = qw(bundling no_ignore_case permute); | ||
| 22 | push @configuration, 'pass_through' | ||
| 23 | if $tool eq 'urpmf' || $tool eq 'urpmi.addmedia'; | ||
| 24 | Getopt::Long::Configure(@configuration); | ||
| 25 | |||
| 26 | # global urpm object to be passed by the main program | ||
| 27 | my $urpm; | ||
| 28 | |||
| 29 | # stores the values of the command-line options | ||
| 30 | our %options = (verbose => 0); | ||
| 31 | |||
| 32 | # used by urpmf | ||
| 33 | sub add_param_closure { | ||
| 34 | my (@tags) = @_; | ||
| 35 | return sub { $::qf .= join $::separator, '', map { "%$_" } @tags }; | ||
| 36 | } | ||
| 37 | |||
| 38 | # debug code to display a nice message when exiting, | ||
| 39 | # to ensure f*cking code (eg: Sys::Syslog) won't exit and break graphical interfaces | ||
| 40 | END { $::debug_exit and print STDERR "EXITING (pid=$$)\n" } | ||
| 41 | |||
| 42 | sub set_debug { | ||
| 43 | my ($urpm) = @_; | ||
| 44 | $::debug_exit = 1; | ||
| 45 | $options{verbose}++; | ||
| 46 | $urpm->{debug} = $urpm->{debug_URPM} = sub { print STDERR "$_[0]\n" }; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub set_verbose { | ||
| 50 | $options{verbose} += $_[0]; | ||
| 51 | } | ||
| 52 | |||
| 53 | # options specifications for Getopt::Long | ||
| 54 | |||
| 55 | my %options_spec_all = ( | ||
| 56 | 'debug' => sub { set_debug($urpm) }, | ||
| 57 | 'debug-librpm' => sub { URPM::setVerbosity(7) }, # 7 == RPMLOG_DEBUG | ||
| 58 | 'q|quiet' => sub { set_verbose(-1) }, | ||
| 59 | 'v|verbose' => sub { set_verbose(1) }, | ||
| 60 | 'urpmi-root=s' => sub { urpm::set_files($urpm, $_[1]) }, | ||
| 61 | 'wait-lock' => \$options{wait_lock}, | ||
| 62 | 'use-copied-hdlist' => sub { $urpm->{options}{use_copied_hdlist} = 1 }, | ||
| 63 | 'tune-rpm=s' => sub { urpm::set_tune_rpm($urpm, $_[1]) }, | ||
| 64 | "no-locales" => sub { $urpm::msg::no_translation = 1 }, | ||
| 65 | "version" => sub { require urpm; print "$tool $urpm::VERSION\n"; exit(0) }, | ||
| 66 | "help|h" => sub { | ||
| 67 | if (defined &::usage) { ::usage() } else { die "No help defined\n" } | ||
| 68 | }, | ||
| 69 | ); | ||
| 70 | |||
| 71 | my %options_spec = ( | ||
| 72 | |||
| 73 | # warning: for gurpm, urpm is _not_ a real urpmi object, only options should be altered: | ||
| 74 | gurpmi => { | ||
| 75 | 'media|mediums=s' => sub { $urpm->{options}{media} = 1 }, | ||
| 76 | 'searchmedia|search-media=s' => sub { $urpm->{options}{searchmedia} = 1 }, | ||
| 77 | }, | ||
| 78 | |||
| 79 | urpmi => { | ||
| 80 | update => \$::update, | ||
| 81 | 'media|mediums=s' => \$::media, | ||
| 82 | 'excludemedia|exclude-media=s' => \$::excludemedia, | ||
| 83 | 'sortmedia|sort-media=s' => \$::sortmedia, | ||
| 84 | 'searchmedia|search-media=s' => \$::searchmedia, | ||
| 85 | 'synthesis=s' => \$options{synthesis}, | ||
| 86 | auto => sub { $urpm->{options}{auto} = 1 }, | ||
| 87 | 'allow-medium-change' => \$::allow_medium_change, | ||
| 88 | 'auto-select' => \$::auto_select, | ||
| 89 | 'auto-update' => sub { $::auto_update = $::auto_select = 1 }, | ||
| 90 | 'auto-orphans' => \$options{auto_orphans}, | ||
| 91 | 'no-remove|no-uninstall' => \$::no_remove, | ||
| 92 | 'no-install|noinstall' => \$::no_install, | ||
| 93 | 'keep!' => sub { $urpm->{options}{keep} = $_[1] }, | ||
| 94 | 'logfile=s' => \$::logfile, | ||
| 95 | 'split-level=s' => sub { $urpm->{options}{'split-level'} = $_[1] }, | ||
| 96 | 'split-length=s' => sub { $urpm->{options}{'split-length'} = $_[1] }, | ||
| 97 | 'fuzzy!' => sub { $urpm->{options}{fuzzy} = $_[1] }, | ||
| 98 | 'src|s' => sub { $urpm->{error}("option --src is deprecated, use --buildrequires instead (nb: it doesn't download src.rpm anymore)"); | ||
| 99 | $options{buildrequires} = 1 }, | ||
| 100 | 'buildrequires' => \$options{buildrequires}, | ||
| 101 | 'install-src' => \$::install_src, | ||
| 102 | reinstall => sub { $urpm->{options}{reinstall} = 1 }, | ||
| 103 | clean => sub { $::clean = 1; $::noclean = 0 }, | ||
| 104 | noclean => sub { | ||
| 105 | $::clean = $urpm->{options}{'pre-clean'} = $urpm->{options}{'post-clean'} = 0; | ||
| 106 | $::noclean = 1; | ||
| 107 | }, | ||
| 108 | 'pre-clean!' => sub { $urpm->{options}{'pre-clean'} = $_[1] }, | ||
| 109 | 'post-clean!' => sub { $urpm->{options}{'post-clean'} = $_[1] }, | ||
| 110 | 'no-priority-upgrade' => sub { | ||
| 111 | #- keep this option which is passed by older urpmi. | ||
| 112 | #- since we can't know what the previous_priority_upgrade list was, | ||
| 113 | #- just use a rubbish value which will mean list has changed | ||
| 114 | $options{previous_priority_upgrade} = 'list_has_changed'; | ||
| 115 | }, | ||
| 116 | 'previous-priority-upgrade=s' => \$options{previous_priority_upgrade}, | ||
| 117 | force => \$::force, | ||
| 118 | justdb => \$options{justdb}, | ||
| 119 | replacepkgs => \$options{replacepkgs}, | ||
| 120 | suggests => sub { | ||
| 121 | $urpm->{fatal}(1, "Use --allow-recommends instead of --suggests"); | ||
| 122 | }, | ||
| 123 | 'allow-suggests' => sub { | ||
| 124 | warn "WARNING: --allow-suggests is deprecated. Use --allow-recommends instead\n"; | ||
| 125 | $urpm->{options}{'no-recommends'} = 0 }, | ||
| 126 | 'allow-recommends' => sub { $urpm->{options}{'no-recommends'} = 0 }, | ||
| 127 | 'no-recommends' => sub { $urpm->{options}{'no-recommends'} = 1 }, | ||
| 128 | 'no-suggests' => sub { # COMPAT | ||
| 129 | warn "WARNING: --no-suggests is deprecated. Use --no-recommends instead\n"; | ||
| 130 | $urpm->{options}{'no-recommends'} = 1; | ||
| 131 | }, | ||
| 132 | 'allow-nodeps' => sub { $urpm->{options}{'allow-nodeps'} = 1 }, | ||
| 133 | 'allow-force' => sub { $urpm->{options}{'allow-force'} = 1 }, | ||
| 134 | 'downgrade' => sub { $urpm->{options}{downgrade} = 1 }, | ||
| 135 | 'parallel=s' => \$::parallel, | ||
| 136 | |||
| 137 | 'metalink!' => sub { $urpm->{options}{metalink} = $_[1] }, | ||
| 138 | 'download-all:s' => sub { $urpm->{options}{'download-all'} = $_[1] }, | ||
| 139 | # deprecated in favor of --downloader xxx | ||
| 140 | wget => sub { $urpm->{options}{downloader} = 'wget' }, | ||
| 141 | curl => sub { $urpm->{options}{downloader} = 'curl' }, | ||
| 142 | prozilla => sub { $urpm->{options}{downloader} = 'prozilla' }, | ||
| 143 | aria2 => sub { $urpm->{options}{downloader} = 'aria2' }, | ||
| 144 | 'downloader=s' => sub { $urpm->{options}{downloader} = $_[1] }, | ||
| 145 | |||
| 146 | 'curl-options=s' => sub { $urpm->{options}{'curl-options'} = $_[1] }, | ||
| 147 | 'rsync-options=s' => sub { $urpm->{options}{'rsync-options'} = $_[1] }, | ||
| 148 | 'wget-options=s' => sub { $urpm->{options}{'wget-options'} = $_[1] }, | ||
| 149 | 'prozilla-options=s' => sub { $urpm->{options}{'prozilla-options'} = $_[1] }, | ||
| 150 | 'aria2-options=s' => sub { $urpm->{options}{'aria2-options'} = $_[1] }, | ||
| 151 | 'limit-rate=s' => sub { $urpm->{options}{'limit-rate'} = $_[1] }, | ||
| 152 | 'resume!' => sub { $urpm->{options}{resume} = $_[1] }, | ||
| 153 | 'retry=s' => sub { $urpm->{options}{retry} = $_[1] }, | ||
| 154 | 'proxy=s' => sub { | ||
| 155 | my (undef, $value) = @_; | ||
| 156 | my ($proxy, $port) = urpm::download::parse_http_proxy($value) | ||
| 157 | or die N("bad proxy declaration on command line\n"); | ||
| 158 | $proxy .= ":1080" unless $port; | ||
| 159 | urpm::download::set_cmdline_proxy(http_proxy => "http://$proxy/"); | ||
| 160 | }, | ||
| 161 | 'proxy-user=s' => sub { | ||
| 162 | my (undef, $value) = @_; | ||
| 163 | if ($value eq 'ask') { #- should prompt for user/password | ||
| 164 | urpm::download::set_cmdline_proxy(ask => 1); | ||
| 165 | } else { | ||
| 166 | $value =~ /(.+):(.+)/ or die N("bad proxy declaration on command line\n"); | ||
| 167 | urpm::download::set_cmdline_proxy(user => $1, pwd => $2); | ||
| 168 | } | ||
| 169 | }, | ||
| 170 | 'bug=s' => \$options{bug}, | ||
| 171 | 'env=s' => \$::env, | ||
| 172 | 'verify-rpm!' => sub { $urpm->{options}{'verify-rpm'} = $_[1] }, | ||
| 173 | 'strict-arch!' => sub { $urpm->{options}{'strict-arch'} = $_[1] }, | ||
| 174 | 'norebuild!' => sub { $urpm->{options}{'build-hdlist-on-error'} = !$_[1] }, | ||
| 175 | 'test!' => \$::test, | ||
| 176 | 'debug__do_not_install' => \$options{debug__do_not_install}, | ||
| 177 | deploops => \$options{deploops}, | ||
| 178 | 'skip=s' => \$options{skip}, | ||
| 179 | 'prefer=s' => \$options{prefer}, | ||
| 180 | 'root=s' => sub { set_root($urpm, $_[1]) }, | ||
| 181 | 'use-distrib=s' => sub { | ||
| 182 | $options{usedistrib} = $_[1]; | ||
| 183 | return if !$>; | ||
| 184 | $urpm->{cachedir} = $urpm->valid_cachedir; | ||
| 185 | $urpm->{statedir} = $urpm->valid_statedir; | ||
| 186 | }, | ||
| 187 | 'probe-synthesis' => sub { $options{probe_with} = 'synthesis' }, | ||
| 188 | 'probe-hdlist' => sub { $options{probe_with} = 'synthesis' }, #- ignored, kept for compatibility | ||
| 189 | 'excludepath|exclude-path=s' => sub { $urpm->{options}{excludepath} = $_[1] }, | ||
| 190 | 'excludedocs|exclude-docs' => sub { $urpm->{options}{excludedocs} = 1 }, | ||
| 191 | 'ignoresize' => sub { $urpm->{options}{ignoresize} = 1 }, | ||
| 192 | 'ignorearch' => sub { $urpm->{options}{ignorearch} = 1 }, | ||
| 193 | noscripts => sub { $urpm->{options}{noscripts} = 1 }, | ||
| 194 | replacefiles => sub { $urpm->{options}{replacefiles} = 1 }, | ||
| 195 | 'more-choices' => sub { $urpm->{options}{morechoices} = 1 }, | ||
| 196 | 'expect-install!' => \$::urpm::main_loop::expect_install, | ||
| 197 | 'nolock' => \$options{nolock}, | ||
| 198 | restricted => \$::restricted, | ||
| 199 | 'force-key' => \$::forcekey, | ||
| 200 | a => \$::all, | ||
| 201 | p => sub { $::use_provides = 1 }, | ||
| 202 | P => sub { $::use_provides = 0 }, | ||
| 203 | y => sub { $urpm->{options}{fuzzy} = 1 }, | ||
| 204 | z => sub { $urpm->{options}{compress} = 1 }, | ||
| 205 | }, | ||
| 206 | |||
| 207 | urpme => { | ||
| 208 | a => \$options{matches}, | ||
| 209 | restricted => \$options{restricted}, | ||
| 210 | }, | ||
| 211 | |||
| 212 | #- see also below, autogenerated callbacks | ||
| 213 | urpmf => { | ||
| 214 | conffiles => add_param_closure('conf_files'), | ||
| 215 | debug => \$::debug, | ||
| 216 | 'literal|l' => \$::literal, | ||
| 217 | name => sub { | ||
| 218 | add_param_closure('name')->(); | ||
| 219 | #- Remove default tag in front if --name is explicitly given | ||
| 220 | $::qf =~ s/^%default:?//; | ||
| 221 | }, | ||
| 222 | 'qf=s' => \$::qf, | ||
| 223 | 'uniq|u' => \$::uniq, | ||
| 224 | m => add_param_closure('media'), | ||
| 225 | i => sub { $::pattern = 'i' }, | ||
| 226 | I => sub { $::pattern = '' }, | ||
| 227 | f => sub { $::full = 1 }, | ||
| 228 | 'F=s' => sub { $::separator = $_[1] }, | ||
| 229 | 'e=s' => sub { $::expr .= "($_[1])" }, | ||
| 230 | a => sub { add_urpmf_binary_op('&&', '-a') }, | ||
| 231 | o => sub { add_urpmf_binary_op('||', '-o') }, | ||
| 232 | '<>' => sub { | ||
| 233 | my $p = shift; | ||
| 234 | if ($p =~ /^-?([!()])$/) { | ||
| 235 | # This is for -! -( -) | ||
| 236 | my $op = $1; | ||
| 237 | $op eq ')' ? add_urpmf_close_paren() : add_urpmf_unary_op($op); | ||
| 238 | } | ||
| 239 | elsif ($p =~ /^--?(.+)/) { | ||
| 240 | # unrecognized option | ||
| 241 | die "Unknown option: $1\n"; | ||
| 242 | } | ||
| 243 | else { | ||
| 244 | # This is for non-option arguments. | ||
| 245 | add_urpmf_parameter($p); | ||
| 246 | } | ||
| 247 | }, | ||
| 248 | }, | ||
| 249 | |||
| 250 | urpmq => { | ||
| 251 | update => \$options{update}, | ||
| 252 | 'media|mediums=s' => \$options{media}, | ||
| 253 | 'excludemedia|exclude-media=s' => \$options{excludemedia}, | ||
| 254 | 'sortmedia|sort-media=s' => \$options{sortmedia}, | ||
| 255 | 'searchmedia|search-media=s' => \$options{searchmedia}, | ||
| 256 | 'auto-select' => sub { | ||
| 257 | $options{deps} = $options{upgrade} = $options{auto_select} = 1; | ||
| 258 | }, | ||
| 259 | 'fuzzy|y' => sub { $urpm->{options}{fuzzy} = 1; $options{all} = 1 }, | ||
| 260 | 'not-available' => \$options{not_available}, | ||
| 261 | keep => \$options{keep}, | ||
| 262 | list => \$options{list}, | ||
| 263 | changelog => \$options{changelog}, | ||
| 264 | conflicts => \$options{conflicts}, | ||
| 265 | obsoletes => \$options{obsoletes}, | ||
| 266 | provides => \$options{provides}, | ||
| 267 | sourcerpm => \$options{sourcerpm}, | ||
| 268 | 'summary|S' => \$options{summary}, | ||
| 269 | recommends => sub { | ||
| 270 | $options{recommends} = 1; | ||
| 271 | }, | ||
| 272 | suggests => sub { | ||
| 273 | $urpm->{error}("You should now use --recommends."); | ||
| 274 | $options{recommends} = 1; | ||
| 275 | }, | ||
| 276 | 'list-media:s' => sub { $options{list_media} = $_[1] || 'all' }, | ||
| 277 | 'list-url' => \$options{list_url}, | ||
| 278 | 'list-nodes' => \$options{list_nodes}, | ||
| 279 | 'list-aliases' => \$options{list_aliases}, | ||
| 280 | 'ignorearch' => \$options{ignorearch}, | ||
| 281 | 'dump-config' => \$options{dump_config}, | ||
| 282 | 'src|s' => \$options{src}, | ||
| 283 | sources => \$options{sources}, | ||
| 284 | force => \$options{force}, | ||
| 285 | 'parallel=s' => \$options{parallel}, | ||
| 286 | 'env=s' => \$options{env}, | ||
| 287 | requires => sub { $options{requires} = 1 }, | ||
| 288 | 'requires-recursive|d' => \$options{deps}, | ||
| 289 | u => \$options{upgrade}, | ||
| 290 | a => \$options{all}, | ||
| 291 | 'm|M' => sub { $options{deps} = $options{upgrade} = 1 }, | ||
| 292 | c => \$options{complete}, | ||
| 293 | g => \$options{group}, | ||
| 294 | 'whatprovides|p' => \$options{use_provides}, | ||
| 295 | P => sub { $options{use_provides} = 0 }, | ||
| 296 | R => sub { $urpm->{error}($options{what_requires} ? | ||
| 297 | "option -RR is deprecated, use --whatrequires-recursive instead" : | ||
| 298 | "option -R is deprecated, use --whatrequires instead"); | ||
| 299 | $options{what_requires} and $options{what_requires_recursive} = 1; | ||
| 300 | $options{what_requires} = 1 }, | ||
| 301 | whatrequires => sub { $options{what_requires} = 1 }, | ||
| 302 | 'whatrequires-recursive' => sub { $options{what_requires_recursive} = $options{what_requires} = 1 }, | ||
| 303 | Y => sub { $urpm->{options}{fuzzy} = 1; $options{all} = $options{caseinsensitive} = 1 }, | ||
| 304 | i => \$options{info}, | ||
| 305 | l => \$options{files}, | ||
| 306 | r => sub { | ||
| 307 | $options{version} = $options{release} = 1; | ||
| 308 | }, | ||
| 309 | f => sub { | ||
| 310 | $options{version} = $options{release} = $options{arch} = 1; | ||
| 311 | }, | ||
| 312 | '<>' => sub { | ||
| 313 | my $x = $_[0]; | ||
| 314 | if ($x =~ /\.rpm$/) { | ||
| 315 | if (-r $x) { push @::files, $x } | ||
| 316 | else { | ||
| 317 | print STDERR N("urpmq: cannot read rpm file \"%s\"\n", $x); | ||
| 318 | $urpm::postponed_code = 1; | ||
| 319 | } | ||
| 320 | } elsif ($x =~ /^--?(.+)/) { # unrecognized option | ||
| 321 | die "Unknown option: $1\n"; | ||
| 322 | } else { | ||
| 323 | if ($options{src}) { | ||
| 324 | push @::src_names, $x; | ||
| 325 | } else { | ||
| 326 | push @::names, $x; | ||
| 327 | } | ||
| 328 | $options{src} = 0; #- reset switch for next package. | ||
| 329 | } | ||
| 330 | }, | ||
| 331 | }, | ||
| 332 | |||
| 333 | 'urpmi.update' => { | ||
| 334 | a => \$options{all}, | ||
| 335 | c => sub {}, # obsolete | ||
| 336 | f => sub { ++$options{force}; $options{probe_with} = 'rpms' if $options{force} == 2 }, | ||
| 337 | z => sub { ++$options{compress} }, | ||
| 338 | update => \$options{update}, | ||
| 339 | 'ignore!' => sub { $options{ignore} = $_[1] }, | ||
| 340 | 'force-key' => \$options{forcekey}, | ||
| 341 | 'no-md5sum' => \$options{nomd5sum}, | ||
| 342 | 'noa|d' => \my $_dummy, #- default, kept for compatibility | ||
| 343 | 'norebuild!' => sub { $urpm->{options}{'build-hdlist-on-error'} = !$_[1]; $options{force} = 0 }, | ||
| 344 | 'probe-rpms' => sub { $options{probe_with} = 'rpms' }, | ||
| 345 | '<>' => sub { | ||
| 346 | my ($p) = @_; | ||
| 347 | if ($p =~ /^--?(.+)/) { # unrecognized option | ||
| 348 | die "Unknown option: $1\n"; | ||
| 349 | } | ||
| 350 | push @::cmdline, $p; | ||
| 351 | }, | ||
| 352 | }, | ||
| 353 | |||
| 354 | 'urpmi.addmedia' => { | ||
| 355 | 'xml-info=s' => \$options{'xml-info'}, | ||
| 356 | 'no-probe' => sub { $options{probe_with} = undef }, | ||
| 357 | distrib => sub { $options{distrib} = 1 }, | ||
| 358 | 'mirrorlist:s' => sub { $options{mirrorlist} = $_[1] || '$MIRRORLIST' }, | ||
| 359 | zeroconf => sub { $options{zeroconf} = 1 }, | ||
| 360 | interactive => sub { $options{interactive} = 1 }, | ||
| 361 | 'all-media' => sub { $options{allmedia} = 1 }, | ||
| 362 | virtual => \$options{virtual}, | ||
| 363 | nopubkey => \$options{nopubkey}, | ||
| 364 | raw => \$options{raw}, | ||
| 365 | 'verify-rpm!' => sub { ${options}{'verify-rpm'} = $_[1] }, | ||
| 366 | 'ignorearch' => sub { $options{ignorearch} = 1 }, | ||
| 367 | }, | ||
| 368 | |||
| 369 | ); | ||
| 370 | |||
| 371 | # generate urpmf options callbacks | ||
| 372 | sub add_urpmf_cmdline_tags { | ||
| 373 | foreach my $k (@_) { | ||
| 374 | $options_spec{urpmf}{$k} ||= add_param_closure($k); | ||
| 375 | } | ||
| 376 | } | ||
| 377 | |||
| 378 | sub _current_urpmf_left_expr() { | ||
| 379 | my $left = $::left_expr || $::expr && "$::expr || " || ''; | ||
| 380 | $::left_expr = $::expr = undef; | ||
| 381 | $left; | ||
| 382 | } | ||
| 383 | |||
| 384 | sub add_urpmf_binary_op { | ||
| 385 | my ($op, $cmdline) = @_; | ||
| 386 | $::left_expr and $urpm->{fatal}(1, N("unexpected expression %s", $::left_expr)); | ||
| 387 | $::expr or $urpm->{fatal}(1, N("missing expression before %s", $cmdline)); | ||
| 388 | |||
| 389 | ($::expr, $::left_expr) = (undef, $::expr . " $op "); | ||
| 390 | } | ||
| 391 | sub add_urpmf_unary_op { | ||
| 392 | my ($op) = @_; | ||
| 393 | $::expr and $urpm->{fatal}(1, N("unexpected expression %s (suggestion: use -a or -o ?)", $::expr)); | ||
| 394 | ($::expr, $::left_expr) = (undef, $::left_expr . $op); | ||
| 395 | } | ||
| 396 | sub add_urpmf_close_paren() { | ||
| 397 | $::expr or $urpm->{fatal}(1, N("no expression to close")); | ||
| 398 | $::expr .= ')'; | ||
| 399 | } | ||
| 400 | sub add_urpmf_parameter { | ||
| 401 | my ($p) = @_; | ||
| 402 | |||
| 403 | if ($::literal) { | ||
| 404 | $p = quotemeta $p; | ||
| 405 | } else { | ||
| 406 | $p =~ /\([^?|]*\)$/ and $urpm->{error}(N("by default urpmf awaits a regexp. you should use option \"--literal\"")); | ||
| 407 | push @::raw_non_literals, $p; | ||
| 408 | # quote "+" chars for packages with + in their names | ||
| 409 | $p =~ s/\+/\\+/g; | ||
| 410 | } | ||
| 411 | $::expr = _current_urpmf_left_expr() . "m{$p}" . $::pattern; | ||
| 412 | } | ||
| 413 | |||
| 414 | # common options setup | ||
| 415 | |||
| 416 | foreach my $k ('allow-medium-change', 'auto', 'auto-select', 'clean', 'download-all:s', 'force', 'expect-install!', 'justdb', 'no-priority-upgrade', 'noscripts', 'replacefiles', 'p', 'P', 'previous-priority-upgrade=s', 'root=s', 'test!', 'verify-rpm!', 'update', | ||
| 417 | 'split-level=s', 'split-length=s') | ||
| 418 | { | ||
| 419 | $options_spec{gurpmi}{$k} = $options_spec{urpmi}{$k}; | ||
| 420 | } | ||
| 421 | $options_spec{gurpmi2} = $options_spec{gurpmi}; | ||
| 422 | |||
| 423 | foreach my $k ("test!", "force", "root=s", "use-distrib=s", 'env=s', | ||
| 424 | 'noscripts', 'auto', 'auto-orphans', 'justdb', | ||
| 425 | "parallel=s") | ||
| 426 | { | ||
| 427 | $options_spec{urpme}{$k} = $options_spec{urpmi}{$k}; | ||
| 428 | } | ||
| 429 | foreach my $k ("root=s", "nolock", "use-distrib=s", "skip=s", "prefer=s", "synthesis=s", 'no-recommends', 'no-suggests', 'allow-recommends', 'allow-suggests', 'auto-orphans') | ||
| 430 | { | ||
| 431 | $options_spec{urpmq}{$k} = $options_spec{urpmi}{$k}; | ||
| 432 | } | ||
| 433 | |||
| 434 | foreach my $k ("update", "media|mediums=s", | ||
| 435 | "excludemedia|exclude-media=s", "sortmedia|sort-media=s", "use-distrib=s", | ||
| 436 | "synthesis=s", "env=s") | ||
| 437 | { | ||
| 438 | $options_spec{urpmf}{$k} = $options_spec{urpmi}{$k}; | ||
| 439 | } | ||
| 440 | |||
| 441 | foreach my $k ("wget", "curl", "prozilla", "aria2", 'downloader=s', "proxy=s", "proxy-user=s", | ||
| 442 | 'limit-rate=s', 'metalink!', | ||
| 443 | "wget-options=s", "curl-options=s", "rsync-options=s", "prozilla-options=s", "aria2-options=s") | ||
| 444 | { | ||
| 445 | $options_spec{'urpmi.addmedia'}{$k} = | ||
| 446 | $options_spec{'urpmi.update'}{$k} = | ||
| 447 | $options_spec{urpmq}{$k} = $options_spec{urpmi}{$k}; | ||
| 448 | } | ||
| 449 | |||
| 450 | foreach my $k ("f", "z", "update", "norebuild!", "probe-rpms", '<>') | ||
| 451 | { | ||
| 452 | $options_spec{'urpmi.addmedia'}{$k} = $options_spec{'urpmi.update'}{$k}; | ||
| 453 | } | ||
| 454 | |||
| 455 | foreach my $k ("no-md5sum") | ||
| 456 | { | ||
| 457 | $options_spec{urpmi}{$k} = $options_spec{'urpmi.addmedia'}{$k} = $options_spec{'urpmi.update'}{$k}; | ||
| 458 | } | ||
| 459 | |||
| 460 | foreach my $k ("a", '<>') { | ||
| 461 | $options_spec{'urpmi.removemedia'}{$k} = $options_spec{'urpmi.update'}{$k}; | ||
| 462 | } | ||
| 463 | foreach my $k ("y") { | ||
| 464 | $options_spec{'urpmi.removemedia'}{$k} = $options_spec{urpmi}{$k}; | ||
| 465 | } | ||
| 466 | |||
| 467 | foreach my $k ("probe-synthesis", "probe-hdlist") # probe-hdlist is obsolete | ||
| 468 | { | ||
| 469 | $options_spec{'urpmi.addmedia'}{$k} = | ||
| 470 | $options_spec{urpme}{$k} = | ||
| 471 | $options_spec{urpmq}{$k} = $options_spec{urpmi}{$k}; | ||
| 472 | } | ||
| 473 | |||
| 474 | sub set_root { | ||
| 475 | my ($urpm, $root) = @_; | ||
| 476 | |||
| 477 | $urpm->{root} = file2absolute_file($root); | ||
| 478 | |||
| 479 | if (!-d $urpm->{root}) { | ||
| 480 | $urpm->{fatal}->(9, N("chroot directory doesn't exist")); | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 | sub set_verbosity() { | ||
| 485 | $options{verbose} >= 0 or $urpm->{info} = sub {}; | ||
| 486 | $options{verbose} > 0 or $urpm->{log} = sub {}; | ||
| 487 | } | ||
| 488 | |||
| 489 | sub parse_cmdline { | ||
| 490 | my %args = @_; | ||
| 491 | $urpm = $args{urpm}; | ||
| 492 | foreach my $k (keys %{$args{defaults} || {}}) { | ||
| 493 | $options{$k} = $args{defaults}{$k}; | ||
| 494 | } | ||
| 495 | my $ret = GetOptions(%{$options_spec{$tool}}, %options_spec_all); | ||
| 496 | |||
| 497 | set_verbosity(); | ||
| 498 | |||
| 499 | $urpm->{tune_rpm} and urpm::tune_rpm($urpm); | ||
| 500 | |||
| 501 | if ($tool ne 'urpmi.addmedia' && $tool ne 'urpmi.update' && | ||
| 502 | $options{probe_with} && !$options{usedistrib}) { | ||
| 503 | die N("Can't use %s without %s", "--probe-$options{probe_with}", "--use-distrib"); | ||
| 504 | } | ||
| 505 | if ($options{probe_with} && $options{probe_with} eq 'rpms' && $options{virtual}) { | ||
| 506 | die N("Can't use %s with %s", "--probe-rpms", "--virtual"); | ||
| 507 | } | ||
| 508 | if ($options{nolock} && $options{wait_lock}) { | ||
| 509 | warn N("Can't use %s with %s", "--wait-lock", "--nolock") . "\n"; | ||
| 510 | } | ||
| 511 | if ($tool eq 'urpmf' && @ARGV && $ARGV[0] eq '--') { | ||
| 512 | if (@ARGV == 2) { | ||
| 513 | add_urpmf_parameter($ARGV[1]); | ||
| 514 | $ret = 1; | ||
| 515 | } | ||
| 516 | else { | ||
| 517 | die N("Too many arguments\n"); | ||
| 518 | } | ||
| 519 | } | ||
| 520 | $ret; | ||
| 521 | } | ||
| 522 | |||
| 523 | sub copyright { | ||
| 524 | my ($prog_name, @copyrights) = @_; | ||
| 525 | N("%s version %s | ||
| 526 | %s | ||
| 527 | This is free software and may be redistributed under the terms of the GNU GPL. | ||
| 528 | |||
| 529 | usage: | ||
| 530 | ", $prog_name, $urpm::VERSION, | ||
| 531 | join("\n", map { N("Copyright (C) %s by %s", @$_) } @copyrights) | ||
| 532 | ); | ||
| 533 | } | ||
| 534 | |||
| 535 | 1; | ||
| 536 | |||
| 537 | |||
| 538 | =head1 NAME | ||
| 539 | |||
| 540 | urpm::args - command-line argument parser for the urpm* tools | ||
| 541 | |||
| 542 | =head1 SYNOPSIS | ||
| 543 | |||
| 544 | urpm::args::parse_cmdline(); | ||
| 545 | |||
| 546 | =head1 DESCRIPTION | ||
| 547 | |||
| 548 | =head1 COPYRIGHT | ||
| 549 | |||
| 550 | Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 MandrakeSoft SA | ||
| 551 | |||
| 552 | Copyright (C) 2005-2010 Mandriva SA | ||
| 553 | |||
| 554 | Copyright (C) 2011-2020 Mageia | ||
| 555 | |||
| 556 | =for vim:ts=8:sts=4:sw=4 | ||
| 557 | |||
| 558 | =cut | ||