Unverified Commit 811f1ad9 authored by Michael Thomsen's avatar Michael Thomsen Committed by GitHub

Forward missing pub commands (#30115)

parent 3fe81026
...@@ -15,6 +15,14 @@ class PackagesCommand extends FlutterCommand { ...@@ -15,6 +15,14 @@ class PackagesCommand extends FlutterCommand {
addSubcommand(PackagesGetCommand('get', false)); addSubcommand(PackagesGetCommand('get', false));
addSubcommand(PackagesGetCommand('upgrade', true)); addSubcommand(PackagesGetCommand('upgrade', true));
addSubcommand(PackagesTestCommand()); addSubcommand(PackagesTestCommand());
addSubcommand(PackagesForwardCommand('downgrade', 'Downgrade packages in a Flutter project', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('publish', 'Publish the current package to pub.dartlang.org', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('deps', 'Print package dependencies', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('run', 'Run an executable from a package', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('cache', 'Work with the Pub system cache'));
addSubcommand(PackagesForwardCommand('version', 'Print Pub version'));
addSubcommand(PackagesForwardCommand('uploader', 'Manage uploaders for a package on pub.dartlang.org'));
addSubcommand(PackagesForwardCommand('global', 'Work with Pub global packages'));
addSubcommand(PackagesPassthroughCommand()); addSubcommand(PackagesPassthroughCommand());
} }
...@@ -129,6 +137,37 @@ class PackagesTestCommand extends FlutterCommand { ...@@ -129,6 +137,37 @@ class PackagesTestCommand extends FlutterCommand {
} }
} }
class PackagesForwardCommand extends FlutterCommand {
PackagesForwardCommand(this._commandName, this._description, {bool requiresPubspec = false}) {
if (requiresPubspec) {
requiresPubspecYaml();
}
}
final String _commandName;
final String _description;
@override
String get name => _commandName;
@override
String get description {
return '$_description.\n'
'This runs the "pub" tool in a Flutter context.';
}
@override
String get invocation {
return '${runner.executableName} packages $_commandName [<arguments...>]';
}
@override
Future<FlutterCommandResult> runCommand() async {
await pub(<String>[_commandName]..addAll(argResults.rest), context: PubContext.pubForward, retry: false);
return null;
}
}
class PackagesPassthroughCommand extends FlutterCommand { class PackagesPassthroughCommand extends FlutterCommand {
PackagesPassthroughCommand() { PackagesPassthroughCommand() {
requiresPubspecYaml(); requiresPubspecYaml();
......
...@@ -41,6 +41,7 @@ class PubContext { ...@@ -41,6 +41,7 @@ class PubContext {
static final PubContext interactive = PubContext._(<String>['interactive']); static final PubContext interactive = PubContext._(<String>['interactive']);
static final PubContext pubGet = PubContext._(<String>['get']); static final PubContext pubGet = PubContext._(<String>['get']);
static final PubContext pubUpgrade = PubContext._(<String>['upgrade']); static final PubContext pubUpgrade = PubContext._(<String>['upgrade']);
static final PubContext pubForward = PubContext._(<String>['forward']);
static final PubContext runTest = PubContext._(<String>['run_test']); static final PubContext runTest = PubContext._(<String>['run_test']);
static final PubContext flutterTests = PubContext._(<String>['flutter_tests']); static final PubContext flutterTests = PubContext._(<String>['flutter_tests']);
......
...@@ -308,7 +308,7 @@ void main() { ...@@ -308,7 +308,7 @@ void main() {
Stdio: () => mockStdio, Stdio: () => mockStdio,
}); });
testUsingContext('publish', () async { testUsingContext('pub publish', () async {
final PromptingProcess process = PromptingProcess(); final PromptingProcess process = PromptingProcess();
mockProcessManager.processFactory = (List<String> commands) => process; mockProcessManager.processFactory = (List<String> commands) => process;
final Future<void> runPackages = createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'pub', 'publish']); final Future<void> runPackages = createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'pub', 'publish']);
...@@ -331,5 +331,84 @@ void main() { ...@@ -331,5 +331,84 @@ void main() {
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio, Stdio: () => mockStdio,
}); });
testUsingContext('publish', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'publish']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'publish');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('deps', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'deps']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'deps');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('cache', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'cache']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'cache');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('version', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'version']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'version');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('uploader', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'uploader']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'uploader');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('global', () async {
await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'global', 'list']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(4));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], '--trace');
expect(commands[2], 'global');
expect(commands[3], 'list');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment