Skip to content

Commit

Permalink
⚡️ Replace the descriptor to allow flexible inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Dec 13, 2024
1 parent b772433 commit 56fd90c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ Specify multiple sdk packages with descriptors.''');
/// Split [arg] on ':' and interpret it with the flags in [argResults] either
/// as an old-style or a new-style descriptor to produce a PackageRef].
_ParseResult _parsePackage(String arg, ArgResults argResults) {
// Removes the leading and the trailing quotes.
// https://github.com/dart-lang/pub/issues/4470
arg = arg.replaceAllMapped(
RegExp(r"""^['"](.*)['"]$"""),
(match) => match.group(1)!,
);

var isDev = argResults.flag('dev');
var isOverride = false;

Expand Down Expand Up @@ -415,7 +422,13 @@ Specify multiple sdk packages with descriptors.''');
if (!packageNameRegExp.hasMatch(packageName)) {
usageException('Not a valid package name: "$packageName"');
}
final descriptor = match.namedGroup('descriptor');

// Explicitly adds a trailing space for commas and colons to help parsing
// a Yaml node. "key:value" will not be recognized as a valid entry.
final descriptor = match.namedGroup('descriptor')?.replaceAllMapped(
RegExp(r'([,:])(\S)'),
(match) => '${match.group(1)} ${match.group(2)}',
);

if (isOverride && descriptor == null) {
usageException('A dependency override needs an explicit descriptor.');
Expand Down

0 comments on commit 56fd90c

Please sign in to comment.