diff options
-rw-r--r-- | urpm/args.pm | 21 | ||||
-rwxr-xr-x | urpmi.removemedia | 51 | ||||
-rwxr-xr-x | urpmi.update | 8 |
3 files changed, 37 insertions, 43 deletions
diff --git a/urpm/args.pm b/urpm/args.pm index 200f39fb..a8260803 100644 --- a/urpm/args.pm +++ b/urpm/args.pm @@ -303,7 +303,7 @@ my %options_spec = ( if ($p =~ /^--?(.+)/) { # unrecognized option die "Unknown option: $1\n"; } - push @::toupdates, $p; + push @::cmdline, $p; }, }, @@ -318,13 +318,6 @@ my %options_spec = ( 'q|quiet' => sub { --$options{verbose} }, 'v|verbose' => sub { ++$options{verbose} }, raw => \$options{raw}, - '<>' => sub { - my ($p) = @_; - if ($p =~ /^--?(.+)/) { # unrecognized option - die "Unknown option: $1\n"; - } - push @::cmdline, $p; - }, }, 'urpmi.recover' => { @@ -390,11 +383,18 @@ foreach my $k ("help|h", "version", "wget", "curl", "prozilla", "proxy=s", "prox foreach my $k ("help|h", "wget", "curl", "prozilla", "proxy=s", "proxy-user=s", "c", "f", "z", "limit-rate=s", "no-md5sum", "update", "norebuild!", - "wget-options=s", "curl-options=s", "rsync-options=s", "prozilla-options=s") + "wget-options=s", "curl-options=s", "rsync-options=s", "prozilla-options=s", '<>') { $options_spec{'urpmi.addmedia'}{$k} = $options_spec{'urpmi.update'}{$k}; } +foreach my $k ("a", "c", 'v|verbose', 'q|quiet', '<>') { + $options_spec{'urpmi.removemedia'}{$k} = $options_spec{'urpmi.update'}{$k}; +} +foreach my $k ("y") { + $options_spec{'urpmi.removemedia'}{$k} = $options_spec{urpmi}{$k}; +} + foreach my $k ("probe-synthesis", "probe-hdlist") { $options_spec{'urpmi.addmedia'}{$k} = @@ -403,7 +403,8 @@ foreach my $k ("probe-synthesis", "probe-hdlist") } foreach my $k ("help|h", "version") { - $options_spec{'urpmi.recover'}{$k} = $options_spec{urpmi}{$k}; + $options_spec{'urpmi.removemedia'}{$k} = + $options_spec{'urpmi.recover'}{$k} = $options_spec{urpmi}{$k}; } sub parse_cmdline { diff --git a/urpmi.removemedia b/urpmi.removemedia index 0bf7d7db..00af3991 100755 --- a/urpmi.removemedia +++ b/urpmi.removemedia @@ -26,31 +26,16 @@ use urpm; use urpm::msg; use urpm::download; use urpm::media; +use urpm::args; $ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"; delete @ENV{qw(ENV BASH_ENV IFS CDPATH)}; my @toremove; -#- default option values -my %options = ( - noclean => 1, - strict_match => 1, - verbose => 1, -); - -{ - my $options_end = 0; - foreach (@ARGV) { - $_ eq '--' and $options_end = 1, next; - unless ($options_end) { - /^--?a$/ and $options{all} = 1, next; - /^--?c$/ and $options{noclean} = 0, next; - /^--?y$/ and $options{strict_match} = 0, next; - /^--?v$/ and $options{verbose} = 1, next; - /^--?q$/ and $options{verbose} = 0, next; - /^-/ and do { - print N("usage: urpmi.removemedia [-a] <name> ... +sub usage { + my ($msg) = @_; + print N("usage: urpmi.removemedia (-a | <name> ...) where <name> is a medium name to remove. ") . N(" --help - print this help message. ") . N(" -a - select all media. @@ -58,33 +43,41 @@ where <name> is a medium name to remove. ") . N(" -y - fuzzy match on media names. ") . N(" -q - quiet mode. ") . N(" -v - verbose mode. -") . (/^--?h(?:elp)$/ ? '' : N("\nunknown options '%s'\n", $_)); - exit 0; - }; - } - push @toremove, $_; - } +") . $msg; + exit 0; } + +#- default option values +$options{noclean} = 1; +$options{strict_match} = 1; + my $urpm = new urpm; + +our @cmdline; #- set by urpm::args +urpm::args::parse_cmdline(urpm => $urpm) or exit(1); + + +$options{verbose} > 0 or $urpm->{log} = sub {}; + if ($< != 0) { $urpm->{fatal}(1, N("Only superuser is allowed to remove media")); } -$options{verbose} > 0 or $urpm->{log} = sub {}; - my $_urpmi_lock = urpm::lock::urpmi_db($urpm, 'exclusive'); urpm::media::read_config($urpm); urpm::download::set_cmdline_proxy(); my @entries = map { $_->{name} } @{$urpm->{media}}; +my @toremove; if ($options{all}) { + !@cmdline or usage(''); @toremove = @entries or die N("nothing to remove (use urpmi.addmedia to add a media)\n"); } else { - @toremove or die N("the entry to remove is missing\n(one of %s)\n", join(", ", @entries)); + @toremove = @cmdline or usage(N("the entry to remove is missing\n(one of %s)\n", join(", ", @entries))); } -my @selected = urpm::media::select_media_by_name($urpm, \@toremove, $options{strict_match}) +my @selected = urpm::media::select_media_by_name($urpm, \@toremove, !$urpm->{options}{fuzzy}) or exit 1; urpm::media::remove_media($urpm, \@selected); diff --git a/urpmi.update b/urpmi.update index fac9cd8d..4dd84128 100755 --- a/urpmi.update +++ b/urpmi.update @@ -55,11 +55,11 @@ where <name> is a medium name to update. $ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"; delete @ENV{qw(ENV BASH_ENV IFS CDPATH)}; -our @toupdates; #- set by urpm::args +our @cmdline; #- set by urpm::args my $urpm = new urpm; $options{force} = 0; -$options{noclean} = $options{verbose} = 1; +$options{noclean} = 1; urpm::args::parse_cmdline(urpm => $urpm) or exit(1); @@ -76,8 +76,8 @@ my @entries = map { $_->{name} } @{$urpm->{media}}; if ($options{all} && !defined $options{ignore}) { @entries == 0 and die N("nothing to update (use urpmi.addmedia to add a media)\n"); } else { - if ($options{all}) { @toupdates = '' } #- select all - urpm::media::select_media($urpm, @toupdates); + if ($options{all}) { @cmdline = '' } #- select all + urpm::media::select_media($urpm, @cmdline); my $something_todo = 0; foreach (@{$urpm->{media}}) { $options{update} && $_->{update} and $_->{modified} = 1; |