Handle String thrown differently

This commit is contained in:
Tobe O 2018-07-14 18:54:38 -04:00
parent 1c9aa76d89
commit 5eb15fcd06
3 changed files with 23 additions and 6 deletions

View file

@ -20,7 +20,11 @@ main(List<String> args) async {
..addCommand(new MakeCommand());
return await runner.run(args).then((_) {}).catchError((exc) {
stderr.writeln("Oops, something went wrong: $exc");
exitCode = 1;
if (exc is String) {
stdout.writeln(exc);
} else {
stderr.writeln("Oops, something went wrong: $exc");
exitCode = 1;
}
});
}

View file

@ -113,8 +113,8 @@ class InitCommand extends Command {
var shouldDelete = prompts.getBool(
"Directory '${projectDir.absolute.path}' already exists. Overwrite it?");
if (shouldDelete)
throw new Exception("Chose not to overwrite existing directory.");
if (!shouldDelete)
throw "Chose not to overwrite existing directory.";
else if (projectDir.absolute.uri.normalizePath().toFilePath() !=
Directory.current.absolute.uri.normalizePath().toFilePath())
await projectDir.delete(recursive: true);

View file

@ -58,8 +58,21 @@ class RenameCommand extends Command {
renamePubspec(Directory dir, String oldName, String newName) async {
// var pubspec = await loadPubspec(dir);
print(cyan.wrap('Renaming your project to `$newName.`'));
print(cyan
.wrap('Note that this does not actually modify your `pubspec.yaml`.'));
var pubspecFile = new File.fromUri(dir.uri.resolve('pubspec.yaml'));
if (await pubspecFile.exists()) {
var contents = await pubspecFile.readAsString(), oldContents = contents;
contents =
contents.replaceAll(new RegExp('name:\\s*$oldName'), 'name: $newName');
if (contents != oldContents) {
await pubspecFile.writeAsString(contents);
}
}
// print(cyan
// .wrap('Note that this does not actually modify your `pubspec.yaml`.'));
// TODO: https://github.com/dart-lang/pubspec_parse/issues/17
// var newPubspec = new Pubspec.fromJson(pubspec.toJson()..['name'] = newName);
// await newPubspec.save(dir);