summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-04-19 12:10:00 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-04-19 12:10:00 +0000
commit7f79f78d1a0af648a116cd1e39a073e051502b9c (patch)
tree8ae051619b77ff62baad7c689d6eadb68401cbcc
parentf2afab2525937a0a6e3028b78ea1763696ac7cee (diff)
downloadurpmi-7f79f78d1a0af648a116cd1e39a073e051502b9c.tar
urpmi-7f79f78d1a0af648a116cd1e39a073e051502b9c.tar.gz
urpmi-7f79f78d1a0af648a116cd1e39a073e051502b9c.tar.bz2
urpmi-7f79f78d1a0af648a116cd1e39a073e051502b9c.tar.xz
urpmi-7f79f78d1a0af648a116cd1e39a073e051502b9c.zip
Some more options refactorisation. The --from option of urpmi.addmedia
was being ignored; fix it.
-rw-r--r--urpm/args.pm44
-rwxr-xr-xurpmi.addmedia18
-rwxr-xr-xurpmi.update4
3 files changed, 39 insertions, 27 deletions
diff --git a/urpm/args.pm b/urpm/args.pm
index f9062727..36e84b79 100644
--- a/urpm/args.pm
+++ b/urpm/args.pm
@@ -21,6 +21,14 @@ my $urpm;
# stores the values of the command-line options
our %options;
+sub import {
+ if ($_[1] eq 'options') {
+ # export the %options hash
+ no strict 'refs';
+ *{caller().'::options'} = \%options;
+ }
+}
+
# options specifications for Getopt::Long
my %options_spec = (
@@ -218,30 +226,30 @@ my %options_spec = (
},
'urpmi.update' => {
- a => \$::options{all},
- c => sub { $::options{noclean} = 0 },
- f => sub { ++$::options{force} },
- z => sub { ++$::options{compress} },
- update => \$::options{update},
- 'force-key' => \$::options{forcekey},
- 'limit-rate=s' => \$::options{limit_rate},
- 'no-md5sum' => \$::options{nomd5sum},
+ a => \$options{all},
+ c => sub { $options{noclean} = 0 },
+ f => sub { ++$options{force} },
+ z => sub { ++$options{compress} },
+ update => \$options{update},
+ 'force-key' => \$options{forcekey},
+ 'limit-rate=s' => \$options{limit_rate},
+ 'no-md5sum' => \$options{nomd5sum},
'noa|d' => \my $dummy, # default, keeped for compatibility
'<>' => sub { push @::toupdates, $_[0] },
},
'urpmi.addmedia' => {
- 'probe-synthesis' => sub { $::options{probe_with} = 'synthesis' },
- 'probe-hdlist' => sub { $::options{probe_with} = 'hdlist' },
- 'no-probe' => sub { $::options{probe_with} = undef },
- distrib => sub { $::options{distrib} = undef },
- 'from=s' => \$::options{mirrors_url},
- 'version=s' => \$::options{version},
- 'arch=s' => \$::options{arch},
- virtual => \$::options{virtual},
+ 'probe-synthesis' => sub { $options{probe_with} = 'synthesis' },
+ 'probe-hdlist' => sub { $options{probe_with} = 'hdlist' },
+ 'no-probe' => sub { $options{probe_with} = undef },
+ distrib => sub { $options{distrib} = undef },
+ 'from=s' => \$options{mirrors_url},
+ 'version=s' => \$options{version},
+ 'arch=s' => \$options{arch},
+ virtual => \$options{virtual},
'<>' => sub {
if ($_[0] =~ /^--distrib-(.*)$/) {
- $::options{distrib} = $1;
+ $options{distrib} = $1;
}
else {
push @::cmdline, $_[0];
@@ -297,6 +305,8 @@ urpm::args - command-line argument parser for the urpm* tools
=head1 SYNOPSIS
+ urpm::args::parse_cmdline();
+
=head1 DESCRIPTION
=cut
diff --git a/urpmi.addmedia b/urpmi.addmedia
index 803dca8c..8157db01 100755
--- a/urpmi.addmedia
+++ b/urpmi.addmedia
@@ -22,7 +22,7 @@
use strict;
use urpm;
-use urpm::args;
+use urpm::args 'options';
use urpm::msg;
# Default mirror list
@@ -79,16 +79,19 @@ and [options] are from
}
sub main {
- our %options;
#- parse /etc/urpmi/mirror.config if present, or use default mandrake mirror.
- if (-e "/etc/urpmi/mirror.config") {
- local (*F, $_);
- open F, "/etc/urpmi/mirror.config";
- while (<F>) {
+ # the --from option overrides this setting.
+ if ($options{mirrors_url}) {
+ $mirrors = $options{$mirrors_url};
+ }
+ elsif (-e "/etc/urpmi/mirror.config") {
+ local $_;
+ open my $fh, "/etc/urpmi/mirror.config";
+ while (<$fh>) {
chomp; s/#.*$//; s/^\s*//; s/\s*$//;
/^url\s*=\s*(.*)/ and $mirrors = $1;
}
- close F;
+ close $fh;
}
$options{force} = 0;
$options{noclean} = 1;
@@ -111,7 +114,6 @@ sub main {
#- -h always set, updates should allow setting update flag.
$options{distrib} eq 'updates' and $options{update} = 1;
#- official site by default.
- $options{from} ||= $mirrors;
#- get default value unless already provided.
unless ($options{version} && $options{arch}) {
my $db = URPM::DB::open;
diff --git a/urpmi.update b/urpmi.update
index 2a591329..5a5abc7f 100755
--- a/urpmi.update
+++ b/urpmi.update
@@ -20,7 +20,7 @@
use strict;
use urpm;
-use urpm::args;
+use urpm::args 'options';
use urpm::msg;
sub usage {
@@ -45,7 +45,7 @@ where <name> is a medium name to update.
}
sub main {
- our (@toupdates, %options);
+ our @toupdates;
my $urpm = new urpm;
$options{force} = 0;