Chromium Code Reviews| Index: bin/generate.dart |
| diff --git a/bin/generate.dart b/bin/generate.dart |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..7eea3462909d833c46c8d0dba5880967897ce920 |
| --- /dev/null |
| +++ b/bin/generate.dart |
| @@ -0,0 +1,87 @@ |
| +#!/usr/bin/env dart |
| + |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import "dart:io"; |
| + |
| +import "package:args/args.dart"; |
| +import "package:googleapis_generator_dependency/googleapis_generator.dart"; |
| + |
| +ArgParser downloadCommandArgParser() { |
| + return new ArgParser() |
| + ..addOption('output-dir', |
| + abbr: 'o', |
| + help: 'Output directory of discovery documents.', |
| + defaultsTo: 'googleapis-discovery-documents'); |
| +} |
| + |
| +ArgParser runConfigCommandArgParser() { |
| + return new ArgParser() |
| + ..addOption('config-file', |
| + help: 'Configuration file describing package generation.', |
| + defaultsTo: 'config.yaml'); |
| +} |
| + |
| +ArgParser globalArgParser() { |
| + return new ArgParser() |
| + ..addCommand('download', downloadCommandArgParser()) |
| + ..addCommand('run_config', runConfigCommandArgParser()) |
| + ..addFlag('help', abbr: 'h', help: 'Displays usage information.'); |
| +} |
| + |
| +ArgResults parseArguments(ArgParser parser, List<String> arguments) { |
| + try { |
| + return parser.parse(arguments); |
| + } on FormatException catch(e) { |
| + dieWithUsage("Error parsing arguments:\n${e.message}\n"); |
| + } |
| +} |
| + |
| +void dieWithUsage([String message]) { |
| + if (message != null) { |
| + print(message); |
| + } |
| + print("Usage:"); |
| + print("The discovery generator has the following sub-commands:"); |
| + print(""); |
| + print(" download"); |
| + print(" run_config"); |
| + print(""); |
| + print("The 'download' subcommand downloads all discovery documents. " |
| + "It takes the following options:"); |
| + print(""); |
| + print(downloadCommandArgParser().usage); |
| + print(""); |
| + print("The 'run_config' subcommand downloads discovery documents and " |
| + "generates one or more API packages based on a configuration file. " |
| + "It takes the following options:"); |
| + print(""); |
| + print(runConfigCommandArgParser().usage); |
| + exit(1); |
| +} |
| + |
| +void main(List<String> arguments) { |
| + var parser = globalArgParser(); |
| + var options = parseArguments(parser, arguments); |
| + var commandOptions = options.command; |
| + var subCommands = ['download', 'generate', 'run_config']; |
|
kustermann
2015/03/12 15:46:42
Remove 'generate' here?
|
| + |
| + if (options['help']) { |
| + dieWithUsage(); |
| + } else if (commandOptions == null || |
| + !subCommands.contains(commandOptions.name)) { |
| + dieWithUsage('Invalid command'); |
| + } |
| + |
| + switch (commandOptions.name) { |
| + case 'download': |
| + downloadDiscoveryDocuments(commandOptions['output-dir']); |
| + break; |
| + case 'run_config': |
| + var configFile = commandOptions['config-file']; |
| + generateFromConfiguration(configFile).then((_) => print('Done!')); |
| + break; |
| + } |
| +} |