Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: pkg/args/lib/args.dart

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/html/templates/html/impl/impl_Storage.darttemplate ('k') | pkg/dartdoc/lib/dartdoc.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This library lets you define parsers for parsing raw command-line arguments 6 * This library lets you define parsers for parsing raw command-line arguments
7 * into a set of options and values using [GNU][] and [POSIX][] style options. 7 * into a set of options and values using [GNU][] and [POSIX][] style options.
8 * 8 *
9 * ## Defining options ## 9 * ## Defining options ##
10 * 10 *
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 489 }
490 490
491 return true; 491 return true;
492 } 492 }
493 493
494 /** 494 /**
495 * Finds the option whose abbreviation is [abbr], or `null` if no option has 495 * Finds the option whose abbreviation is [abbr], or `null` if no option has
496 * that abbreviation. 496 * that abbreviation.
497 */ 497 */
498 _Option _findByAbbr(String abbr) { 498 _Option _findByAbbr(String abbr) {
499 for (var option in _options.getValues()) { 499 for (var option in _options.values) {
500 if (option.abbreviation == abbr) return option; 500 if (option.abbreviation == abbr) return option;
501 } 501 }
502 502
503 return null; 503 return null;
504 } 504 }
505 505
506 /** 506 /**
507 * Get the default value for an option. Useful after parsing to test 507 * Get the default value for an option. Useful after parsing to test
508 * if the user specified something other than the default. 508 * if the user specified something other than the default.
509 */ 509 */
(...skipping 27 matching lines...) Expand all
537 operator [](String name) { 537 operator [](String name) {
538 if (!_options.containsKey(name)) { 538 if (!_options.containsKey(name)) {
539 throw new ArgumentError( 539 throw new ArgumentError(
540 'Could not find an option named "$name".'); 540 'Could not find an option named "$name".');
541 } 541 }
542 542
543 return _options[name]; 543 return _options[name];
544 } 544 }
545 545
546 /** Get the names of the options as a [Collection]. */ 546 /** Get the names of the options as a [Collection]. */
547 Collection<String> get options => _options.getKeys(); 547 Collection<String> get options => _options.keys;
548 } 548 }
549 549
550 class _Option { 550 class _Option {
551 final String name; 551 final String name;
552 final String abbreviation; 552 final String abbreviation;
553 final List allowed; 553 final List allowed;
554 final defaultValue; 554 final defaultValue;
555 final Function callback; 555 final Function callback;
556 final String help; 556 final String help;
557 final Map<String, String> allowedHelp; 557 final Map<String, String> allowedHelp;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 calculateColumnWidths(); 623 calculateColumnWidths();
624 624
625 for (var name in args._optionNames) { 625 for (var name in args._optionNames) {
626 var option = args._options[name]; 626 var option = args._options[name];
627 write(0, getAbbreviation(option)); 627 write(0, getAbbreviation(option));
628 write(1, getLongOption(option)); 628 write(1, getLongOption(option));
629 629
630 if (option.help != null) write(2, option.help); 630 if (option.help != null) write(2, option.help);
631 631
632 if (option.allowedHelp != null) { 632 if (option.allowedHelp != null) {
633 var allowedNames = option.allowedHelp.getKeys(); 633 var allowedNames = option.allowedHelp.keys;
634 allowedNames.sort((a, b) => a.compareTo(b)); 634 allowedNames.sort((a, b) => a.compareTo(b));
635 newline(); 635 newline();
636 for (var name in allowedNames) { 636 for (var name in allowedNames) {
637 write(1, getAllowedTitle(name)); 637 write(1, getAllowedTitle(name));
638 write(2, option.allowedHelp[name]); 638 write(2, option.allowedHelp[name]);
639 } 639 }
640 newline(); 640 newline();
641 } else if (option.allowed != null) { 641 } else if (option.allowed != null) {
642 write(2, buildAllowedList(option)); 642 write(2, buildAllowedList(option));
643 } else if (option.defaultValue != null) { 643 } else if (option.defaultValue != null) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 var option = args._options[name]; 685 var option = args._options[name];
686 686
687 // Make room in the first column if there are abbreviations. 687 // Make room in the first column if there are abbreviations.
688 abbr = max(abbr, getAbbreviation(option).length); 688 abbr = max(abbr, getAbbreviation(option).length);
689 689
690 // Make room for the option. 690 // Make room for the option.
691 title = max(title, getLongOption(option).length); 691 title = max(title, getLongOption(option).length);
692 692
693 // Make room for the allowed help. 693 // Make room for the allowed help.
694 if (option.allowedHelp != null) { 694 if (option.allowedHelp != null) {
695 for (var allowed in option.allowedHelp.getKeys()) { 695 for (var allowed in option.allowedHelp.keys) {
696 title = max(title, getAllowedTitle(allowed).length); 696 title = max(title, getAllowedTitle(allowed).length);
697 } 697 }
698 } 698 }
699 } 699 }
700 700
701 // Leave a gutter between the columns. 701 // Leave a gutter between the columns.
702 title += 4; 702 title += 4;
703 columnWidths = [abbr, title]; 703 columnWidths = [abbr, title];
704 } 704 }
705 705
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 allowedBuffer.add(allowed); 776 allowedBuffer.add(allowed);
777 if (allowed == option.defaultValue) { 777 if (allowed == option.defaultValue) {
778 allowedBuffer.add(' (default)'); 778 allowedBuffer.add(' (default)');
779 } 779 }
780 first = false; 780 first = false;
781 } 781 }
782 allowedBuffer.add(']'); 782 allowedBuffer.add(']');
783 return allowedBuffer.toString(); 783 return allowedBuffer.toString();
784 } 784 }
785 } 785 }
OLDNEW
« no previous file with comments | « lib/html/templates/html/impl/impl_Storage.darttemplate ('k') | pkg/dartdoc/lib/dartdoc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698