Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improve command line parsing.

  • Loading branch information...
commit a064c7f86b779f20aadbef06dbcc0476c6b0cd8b 1 parent a06db7d
Dave Cross authored June 08, 2013

Showing 1 changed file with 18 additions and 12 deletions. Show diff stats Hide diff stats

  1. 30  lotto
30  lotto
@@ -5,21 +5,27 @@ use warnings;
5 5
 use 5.010;
6 6
 
7 7
 my $config = parse_config();
8  
-my $type = shift // 'lotto';
9  
-unless (exists $config->{$type}) {
10  
-  unshift @ARGV, $type;
11  
-  $type = 'lotto';
  8
+
  9
+my ($type, $count) = qw[lotto 1];
  10
+
  11
+my @errs;
  12
+if (@ARGV == 2) {
  13
+  $type = shift;
  14
+  if (! exists $config->{$type}) {
  15
+    push @errs, qq["$type" is not a recognised type of lottery];
  16
+  }
12 17
 }
13 18
 
14  
-my $count;
15  
-if (@ARGV) {
16  
-  if ($ARGV[0] =~ /^\d+$/) {
17  
-    $count = $ARGV[0];
18  
-  } else {
19  
-    die "$ARGV[0] doesn't look like a positive integer\n";
  19
+if (@ARGV == 1) {
  20
+  $count = shift;
  21
+  if ($count !~ /^\d+$/) {
  22
+    push @errs, qq["$count" doesn't look like a positive integer];
20 23
   }
21  
-} else {
22  
-  $count = 1;
  24
+}
  25
+
  26
+if (@ARGV || @errs) {
  27
+  push @errs, 'Usage: lotto [' . join('|', keys %$config) . "] [count]\n";
  28
+  die join "\n", @errs;
23 29
 }
24 30
 
25 31
 for (1 .. $count) {

0 notes on commit a064c7f

Please sign in to comment.
Something went wrong with that request. Please try again.