From 738e081f7ca76876711bc8a39a4c8da0022f1d3a Mon Sep 17 00:00:00 2001 From: "ian%hixie.ch" Date: Thu, 8 Nov 2001 17:09:11 +0000 Subject: [PATCH] Implement default values for arguments. getArgument() and createArgument() now take two parameters like setArgument(). Changed the CommandLine module's createArgument() method so that if the user hits enter at the prompt, the default value is used. Added some comments to clarify what is going on with the 'batch' argument. Changed setArgument() and createArgument() in the Arguments module and createArgument() in the CommandLine module to be more efficient (less array copying). git-svn-id: svn://10.0.0.236/trunk@107678 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/PLIF/PLIF/Input/Arguments.pm | 8 ++++---- mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mozilla/webtools/PLIF/PLIF/Input/Arguments.pm b/mozilla/webtools/PLIF/PLIF/Input/Arguments.pm index 89323ba5542..7fc398b549a 100644 --- a/mozilla/webtools/PLIF/PLIF/Input/Arguments.pm +++ b/mozilla/webtools/PLIF/PLIF/Input/Arguments.pm @@ -46,7 +46,7 @@ sub getArgument { my $self = shift; my($argument) = @_; if (not defined($self->{"argument $argument"})) { - $self->createArgument($argument); + $self->createArgument(@_); } if (wantarray) { return @{$self->{"argument $argument"}}; @@ -106,7 +106,7 @@ sub addArgument { sub setArgument { my $self = shift; my($argument, @value) = @_; - $self->{"argument $argument"} = [@value]; + $self->{"argument $argument"} = \@value; } # modifies the last value for this argument to the new value @@ -139,8 +139,8 @@ sub setCommandArgument { sub createArgument { my $self = shift; - my($argument) = @_; - $self->{"argument $argument"} = []; + my($argument, @default) = @_; + $self->{"argument $argument"} = \@default; } sub propertyExists { diff --git a/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm b/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm index 2f7e37a8529..0e5e1227002 100644 --- a/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm +++ b/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm @@ -79,21 +79,32 @@ sub splitArguments { sub createArgument { my $self = shift; + # @_ also contains @default, but to save copying it about we don't + # use it directly in this method my($argument) = @_; if ($argument eq 'batch') { + # if --batch was not set, then we assume that means that + # we are not in --batch mode... no point asking the user, + # cos if we are, he won't reply, and if he isn't, we know + # he'd say we aren't! :-) $self->setArgument($argument, 0); } else { if ($self->getArgument('batch')) { - $self->SUPER::createArgument($argument); + $self->SUPER::createArgument(@_); } else { $self->warn(5, "going to request '$argument' from user!"); $self->app->output->request($argument); - # get input from user :-) + # get input from user my $term = Term::ReadLine->new($self->app->name); my $value = $term->readline(''); # (the parameter passed is the prompt, if any) # if we cached the input device: # $term->addhistory($value); - $self->setArgument($argument, $value); + if ($value eq '') { + # use default + $self->setArgument(@_); + } else { + $self->setArgument($argument, $value); + } } } }