| OLD | NEW |
| 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 * The main entrypoint for the pub command line application. | 6 * The main entrypoint for the pub command line application. |
| 7 */ | 7 */ |
| 8 #library('pub'); | 8 #library('pub'); |
| 9 | 9 |
| 10 #import('yaml/yaml.dart'); | 10 #import('yaml/yaml.dart'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // TODO(rnystrom): In addition to explicit "help" and "version" commands, | 28 // TODO(rnystrom): In addition to explicit "help" and "version" commands, |
| 29 // should also add special-case support for --help and --version arguments to | 29 // should also add special-case support for --help and --version arguments to |
| 30 // be consistent with other Unix apps. | 30 // be consistent with other Unix apps. |
| 31 final commands = { | 31 final commands = { |
| 32 'list': new ListCommand(), | 32 'list': new ListCommand(), |
| 33 'install': new InstallCommand(), | 33 'install': new InstallCommand(), |
| 34 'update': new UpdateCommand(), | 34 'update': new UpdateCommand(), |
| 35 'version': new VersionCommand() | 35 'version': new VersionCommand() |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to |
| 39 // pass in relevant paths. Eventually these should be either environment |
| 40 // variables or at least a cleaner arg parser. |
| 41 var cacheDir, sdkDir; |
| 42 for (var i = 0; i < args.length; i++) { |
| 43 if (args[i].startsWith('--cachedir=')) { |
| 44 cacheDir = args[i].substring('--cachedir='.length); |
| 45 args.removeRange(i, 1); |
| 46 i--; |
| 47 } else if (args[i].startsWith('--sdkdir=')) { |
| 48 sdkDir = args[i].substring('--sdkdir='.length); |
| 49 args.removeRange(i, 1); |
| 50 i--; |
| 51 } |
| 52 } |
| 53 |
| 38 if (args.length == 0) { | 54 if (args.length == 0) { |
| 39 printUsage(commands); | 55 printUsage(commands); |
| 40 return; | 56 return; |
| 41 } | 57 } |
| 42 | 58 |
| 43 // For consistency with expected unix idioms, support --help, -h, and | 59 // For consistency with expected unix idioms, support --help, -h, and |
| 44 // --version in addition to the regular commands. | 60 // --version in addition to the regular commands. |
| 45 if (args.length == 1) { | 61 if (args.length == 1) { |
| 46 if (args[0] == '--help' || args[0] == '-h') { | 62 if (args[0] == '--help' || args[0] == '-h') { |
| 47 printUsage(commands); | 63 printUsage(commands); |
| 48 return; | 64 return; |
| 49 } | 65 } |
| 50 | 66 |
| 51 if (args[0] == '--version') { | 67 if (args[0] == '--version') { |
| 52 printVersion(); | 68 printVersion(); |
| 53 return; | 69 return; |
| 54 } | 70 } |
| 55 } | 71 } |
| 56 | 72 |
| 57 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to | |
| 58 // pass in relevant paths. Eventually these should be either environment | |
| 59 // variables or at least a cleaner arg parser. | |
| 60 var cacheDir, sdkDir; | |
| 61 for (var i = 0; i < args.length; i++) { | |
| 62 if (args[i].startsWith('--cachedir=')) { | |
| 63 cacheDir = args[i].substring('--cachedir='.length); | |
| 64 args.removeRange(i, 1); | |
| 65 i--; | |
| 66 } else if (args[i].startsWith('--sdkdir=')) { | |
| 67 sdkDir = args[i].substring('--sdkdir='.length); | |
| 68 args.removeRange(i, 1); | |
| 69 i--; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 // TODO(rnystrom): Do we want this to be global? | 73 // TODO(rnystrom): Do we want this to be global? |
| 74 final cache = new SystemCache(cacheDir); | 74 final cache = new SystemCache(cacheDir); |
| 75 | 75 |
| 76 Source.defaultSource = new SdkSource(sdkDir); | 76 Source.defaultSource = new SdkSource(sdkDir); |
| 77 | 77 |
| 78 // Select the command. | 78 // Select the command. |
| 79 final command = commands[args[0]]; | 79 final command = commands[args[0]]; |
| 80 if (command == null) { | 80 if (command == null) { |
| 81 print('Unknown command "${args[0]}".'); | 81 print('Unknown command "${args[0]}".'); |
| 82 print('Run "pub help" to see available commands.'); | 82 print('Run "pub help" to see available commands.'); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // subdirectories until we hit one that looks package-like. For now, just | 138 // subdirectories until we hit one that looks package-like. For now, just |
| 139 // assume the cwd is it. | 139 // assume the cwd is it. |
| 140 Package.load(workingDir).then((pkg) { | 140 Package.load(workingDir).then((pkg) { |
| 141 packagesDir = new PackagesDir(pkg, cache); | 141 packagesDir = new PackagesDir(pkg, cache); |
| 142 onRun(); | 142 onRun(); |
| 143 }); | 143 }); |
| 144 } | 144 } |
| 145 | 145 |
| 146 abstract void onRun(); | 146 abstract void onRun(); |
| 147 } | 147 } |
| OLD | NEW |