Skip to content

Commit

Permalink
Fixes #1310: mason add command ask for overwrite if brick is found
Browse files Browse the repository at this point in the history
  • Loading branch information
koukibadr committed Jul 1, 2024
1 parent 002d1c6 commit 53d875f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
14 changes: 13 additions & 1 deletion packages/mason_cli/lib/src/commands/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ class AddCommand extends MasonCommand with InstallBrickMixin {
}

final progress = logger.progress('Installing ${brick.name}');

final masonYaml = isGlobal ? globalMasonYaml : localMasonYaml;
if (masonYaml.bricks.keys.contains(brick.name)) {
final confirmation = logger.confirm(
'Existing ${brick.name} found, you want to overwrite it?',
defaultValue: true,
);
if (!confirmation) {
progress.fail('Aborted by the user');
return ExitCode.cantCreate.code;
}
}

final cachedBrick = await _addBrick(brick, global: isGlobal);
final file = File(p.join(cachedBrick.path, BrickYaml.file));
final generator = await MasonGenerator.fromBrick(
Expand All @@ -84,7 +97,6 @@ class AddCommand extends MasonCommand with InstallBrickMixin {
(m) => BrickYaml.fromJson(m!),
).copyWith(path: file.path);

final masonYaml = isGlobal ? globalMasonYaml : localMasonYaml;
final masonYamlFile = isGlobal ? globalMasonYamlFile : localMasonYamlFile;
final location = brick.location.version != null
? BrickLocation(version: '^${brickYaml.version}')
Expand Down
28 changes: 14 additions & 14 deletions packages/mason_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: mason_cli
description: >
description: |
Mason CLI allows developers to create and consume reusable templates called bricks.
version: 0.1.0-dev.55
homepage: https://github.com/felangel/mason
repository: https://github.com/felangel/mason
issue_tracker: https://github.com/felangel/mason/issues
documentation: https://docs.brickhub.dev
topics: [mason, cli, template, generator]

version: 0.1.0-dev.56
homepage: 'https://github.com/felangel/mason'
repository: 'https://github.com/felangel/mason'
issue_tracker: 'https://github.com/felangel/mason/issues'
documentation: 'https://docs.brickhub.dev'
topics:
- mason
- cli
- template
- generator
environment:
sdk: ">=3.3.0 <4.0.0"

sdk: '>=3.3.0 <4.0.0'
dependencies:
args: ^2.1.0
checked_yaml: ^2.0.1
Expand All @@ -19,16 +21,14 @@ dependencies:
mason_api: ^0.1.0-dev.10
meta: ^1.7.0
path: ^1.8.0
pub_updater: ">=0.3.0 <0.5.0"
pub_updater: '>=0.3.0 <0.5.0'
watcher: ^1.1.0

dev_dependencies:
build_runner: ^2.0.0
build_verify: ^3.0.0
build_version: ^2.0.0
collection: ^1.15.0
mocktail: ^1.0.0
test: ^1.17.0

executables:
mason:
mason: null

0 comments on commit 53d875f

Please sign in to comment.