Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mason_cli): add <brick> <version> #537

Merged
merged 1 commit into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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