Skip to content

Commit

Permalink
feat(mason_cli): add <brick> <version> (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Oct 12, 2022
1 parent 9eab851 commit 729bdc9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/mason_cli/lib/src/commands/add.dart
Expand Up @@ -54,7 +54,13 @@ class AddCommand extends MasonCommand with InstallBrickMixin {
),
);
} else {
brick = Brick(name: name, location: const BrickLocation(version: 'any'));
if (results.rest.length > 2) {
usageException(
'Too many arguments, expected arguments <name> <version>',
);
}
final version = results.rest.length == 2 ? results.rest.last : 'any';
brick = Brick(name: name, location: BrickLocation(version: version));
}

final cachedBrick = await addBrick(brick, global: isGlobal);
Expand Down
54 changes: 54 additions & 0 deletions packages/mason_cli/test/commands/add_test.dart
Expand Up @@ -255,6 +255,18 @@ void main() {
).called(1);
});

test('exits with code 64 when too many arguments provided', () async {
final result = await commandRunner.run(
['add', 'nonexistent-brick', 'foo', 'bar'],
);
expect(result, equals(ExitCode.usage.code));
verify(
() => logger.err(
'Too many arguments, expected arguments <name> <version>',
),
).called(1);
});

test('adds brick successfully when brick exists', () async {
final result = await commandRunner.run(['add', 'greeting']);
expect(result, equals(ExitCode.success.code));
Expand All @@ -276,6 +288,21 @@ void main() {
);
expect(directoriesDeepEqual(actual, expected), isTrue);
});

test('adds brick successfully when brick exists w/version', () async {
final addResult = await commandRunner.run(
['add', 'greeting', '0.1.0+1'],
);
expect(addResult, equals(ExitCode.success.code));

final listResult = await commandRunner.run(['ls']);
expect(listResult, equals(ExitCode.success.code));
verify(
() => logger.info(
any(that: contains('greeting 0.1.0+1 -> registry.brickhub.dev')),
),
).called(1);
});
});
});

Expand Down Expand Up @@ -414,6 +441,18 @@ void main() {
).called(1);
});

test('exits with code 64 when too many arguments provided', () async {
final result = await commandRunner.run(
['add', '-g', 'nonexistent-brick', 'foo', 'bar'],
);
expect(result, equals(ExitCode.usage.code));
verify(
() => logger.err(
'Too many arguments, expected arguments <name> <version>',
),
).called(1);
});

test('adds brick successfully when brick exists', () async {
final result = await commandRunner.run(['add', '-g', 'greeting']);
expect(result, equals(ExitCode.success.code));
Expand All @@ -435,6 +474,21 @@ void main() {
);
expect(directoriesDeepEqual(actual, expected), isTrue);
});

test('adds brick successfully when brick exists w/version', () async {
final addResult = await commandRunner.run(
['add', '-g', 'greeting', '0.1.0+1'],
);
expect(addResult, equals(ExitCode.success.code));

final listResult = await commandRunner.run(['ls', '-g']);
expect(listResult, equals(ExitCode.success.code));
verify(
() => logger.info(
any(that: contains('greeting 0.1.0+1 -> registry.brickhub.dev')),
),
).called(1);
});
});
});
});
Expand Down

0 comments on commit 729bdc9

Please sign in to comment.