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

Side by Side Diff: bin/generate.dart

Issue 998343002: Add a generate script to generate the googleapis libraries. (Closed) Base URL: https://github.com/dart-lang/googleapis.git@master
Patch Set: Created 5 years, 9 months 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
OLDNEW
(Empty)
1 #!/usr/bin/env dart
2
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
5 // BSD-style license that can be found in the LICENSE file.
6
7 import "dart:io";
8
9 import "package:args/args.dart";
10 import "package:googleapis_generator_dependency/googleapis_generator.dart";
11
12 ArgParser downloadCommandArgParser() {
13 return new ArgParser()
14 ..addOption('output-dir',
15 abbr: 'o',
16 help: 'Output directory of discovery documents.',
17 defaultsTo: 'googleapis-discovery-documents');
18 }
19
20 ArgParser runConfigCommandArgParser() {
21 return new ArgParser()
22 ..addOption('config-file',
23 help: 'Configuration file describing package generation.',
24 defaultsTo: 'config.yaml');
25 }
26
27 ArgParser globalArgParser() {
28 return new ArgParser()
29 ..addCommand('download', downloadCommandArgParser())
30 ..addCommand('run_config', runConfigCommandArgParser())
31 ..addFlag('help', abbr: 'h', help: 'Displays usage information.');
32 }
33
34 ArgResults parseArguments(ArgParser parser, List<String> arguments) {
35 try {
36 return parser.parse(arguments);
37 } on FormatException catch(e) {
38 dieWithUsage("Error parsing arguments:\n${e.message}\n");
39 }
40 }
41
42 void dieWithUsage([String message]) {
43 if (message != null) {
44 print(message);
45 }
46 print("Usage:");
47 print("The discovery generator has the following sub-commands:");
48 print("");
49 print(" download");
50 print(" run_config");
51 print("");
52 print("The 'download' subcommand downloads all discovery documents. "
53 "It takes the following options:");
54 print("");
55 print(downloadCommandArgParser().usage);
56 print("");
57 print("The 'run_config' subcommand downloads discovery documents and "
58 "generates one or more API packages based on a configuration file. "
59 "It takes the following options:");
60 print("");
61 print(runConfigCommandArgParser().usage);
62 exit(1);
63 }
64
65 void main(List<String> arguments) {
66 var parser = globalArgParser();
67 var options = parseArguments(parser, arguments);
68 var commandOptions = options.command;
69 var subCommands = ['download', 'generate', 'run_config'];
kustermann 2015/03/12 15:46:42 Remove 'generate' here?
70
71 if (options['help']) {
72 dieWithUsage();
73 } else if (commandOptions == null ||
74 !subCommands.contains(commandOptions.name)) {
75 dieWithUsage('Invalid command');
76 }
77
78 switch (commandOptions.name) {
79 case 'download':
80 downloadDiscoveryDocuments(commandOptions['output-dir']);
81 break;
82 case 'run_config':
83 var configFile = commandOptions['config-file'];
84 generateFromConfiguration(configFile).then((_) => print('Done!'));
85 break;
86 }
87 }
OLDNEW
« no previous file with comments | « README.md ('k') | lib/googleapis_generator.dart » ('j') | pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698