~gradle-plugins/gradle-templates/trunk

« back to all changes in this revision

Viewing changes to src/main/groovy/templates/TemplatesPlugin.groovy

  • Committer: Eric Berry
  • Date: 2011-04-20 07:19:33 UTC
  • Revision ID: elberry@tellurianring.com-20110420071933-5z6e89sad8jqpiss
Fixing options prompt to check for range validity.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
         consoleMessage += "${inputPrompt} "
42
42
      }
43
43
      try {
44
 
         return Integer.parseInt(System.console().readLine(consoleMessage) ?: defaultValue)
 
44
         def range = 0..options.size() - 1
 
45
         int choice = Integer.parseInt(System.console().readLine(consoleMessage) ?: defaultValue) - 1
 
46
         if(range.containsWithinBounds(choice)) {
 
47
            return choice
 
48
         } else {
 
49
            throw new IllegalArgumentException("Option is not valid.")
 
50
         }
45
51
      } catch (Exception e) {
46
52
         throw new IllegalArgumentException("Option is not valid.", e)
47
53
      }