| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 import "package:args/args.dart"; | 9 import "package:args/args.dart"; |
| 10 import "package:googleapis_generator_dependency/googleapis_generator.dart"; | 10 import "package:googleapis_generator_dependency/googleapis_generator.dart"; |
| 11 | 11 |
| 12 ArgParser downloadCommandArgParser() { | 12 ArgParser downloadCommandArgParser() { |
| 13 return new ArgParser() | 13 return new ArgParser() |
| 14 ..addOption('output-dir', | 14 ..addOption('output-dir', |
| 15 abbr: 'o', | 15 abbr: 'o', |
| 16 help: 'Output directory of discovery documents.', | 16 help: 'Output directory of discovery documents.', |
| 17 defaultsTo: 'googleapis-discovery-documents'); | 17 defaultsTo: 'googleapis-discovery-documents'); |
| 18 } | 18 } |
| 19 | 19 |
| 20 ArgParser runConfigCommandArgParser() { | 20 ArgParser runConfigCommandArgParser() { |
| 21 return new ArgParser() | 21 return new ArgParser() |
| 22 ..addCommand('download') |
| 23 ..addCommand('generate') |
| 22 ..addOption('config-file', | 24 ..addOption('config-file', |
| 23 help: 'Configuration file describing package generation.', | 25 help: 'Configuration file describing package generation.', |
| 24 defaultsTo: 'config.yaml'); | 26 defaultsTo: 'config.yaml'); |
| 25 } | 27 } |
| 26 | 28 |
| 27 ArgParser globalArgParser() { | 29 ArgParser globalArgParser() { |
| 28 return new ArgParser() | 30 return new ArgParser() |
| 29 ..addCommand('download', downloadCommandArgParser()) | 31 ..addCommand('download', downloadCommandArgParser()) |
| 30 ..addCommand('run_config', runConfigCommandArgParser()) | 32 ..addCommand('run_config', runConfigCommandArgParser()) |
| 31 ..addFlag('help', abbr: 'h', help: 'Displays usage information.'); | 33 ..addFlag('help', abbr: 'h', help: 'Displays usage information.'); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } else if (commandOptions == null || | 75 } else if (commandOptions == null || |
| 74 !subCommands.contains(commandOptions.name)) { | 76 !subCommands.contains(commandOptions.name)) { |
| 75 dieWithUsage('Invalid command'); | 77 dieWithUsage('Invalid command'); |
| 76 } | 78 } |
| 77 | 79 |
| 78 switch (commandOptions.name) { | 80 switch (commandOptions.name) { |
| 79 case 'download': | 81 case 'download': |
| 80 downloadDiscoveryDocuments(commandOptions['output-dir']); | 82 downloadDiscoveryDocuments(commandOptions['output-dir']); |
| 81 break; | 83 break; |
| 82 case 'run_config': | 84 case 'run_config': |
| 85 if (commandOptions.command == null || |
| 86 !['download', 'generate'].contains(commandOptions.command.name)) { |
| 87 dieWithUsage('The `run_config` command has only the two subcommands: ' |
| 88 '`download` and `generate`.'); |
| 89 } |
| 90 |
| 83 var configFile = commandOptions['config-file']; | 91 var configFile = commandOptions['config-file']; |
| 84 generateFromConfiguration(configFile).then((_) => print('Done!')); | 92 switch (commandOptions.command.name) { |
| 93 case 'download': |
| 94 downloadFromConfiguration(configFile).then((_) => print('Done!')); |
| 95 break; |
| 96 case 'generate': |
| 97 generateFromConfiguration(configFile); |
| 98 print('Done'); |
| 99 break; |
| 100 } |
| 85 break; | 101 break; |
| 86 } | 102 } |
| 87 } | 103 } |
| OLD | NEW |