Unverified Commit ed118925 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] forward all args to pub (#69784)

Change forwarding command to pass through all args, even -h - this allows flutter to support all of the pub flags without needing to declare them.
parent 1be922c3
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/args.dart';
import '../base/common.dart';
import '../base/os.dart';
import '../build_info.dart';
......@@ -19,7 +21,7 @@ class PackagesCommand extends FlutterCommand {
addSubcommand(PackagesGetCommand('get', false));
addSubcommand(PackagesGetCommand('upgrade', true));
addSubcommand(PackagesTestCommand());
addSubcommand(PackagesPublishCommand());
addSubcommand(PackagesForwardCommand('publish', 'Publish the current package to pub.dartlang.org', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('downgrade', 'Downgrade packages in a Flutter project', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('deps', 'Print package dependencies', requiresPubspec: true));
addSubcommand(PackagesForwardCommand('run', 'Run an executable from a package', requiresPubspec: true));
......@@ -115,7 +117,7 @@ class PackagesGetCommand extends FlutterCommand {
await pub.get(
context: PubContext.pubGet,
directory: directory,
upgrade: upgrade ,
upgrade: upgrade,
offline: boolArg('offline'),
generateSyntheticPackage: flutterProject.manifest.generateSyntheticPackage,
);
......@@ -189,52 +191,16 @@ class PackagesTestCommand extends FlutterCommand {
}
}
class PackagesPublishCommand extends FlutterCommand {
PackagesPublishCommand() {
requiresPubspecYaml();
argParser.addFlag('dry-run',
abbr: 'n',
negatable: false,
help: 'Validate but do not publish the package.',
);
argParser.addFlag('force',
abbr: 'f',
negatable: false,
help: 'Publish without confirmation if there are no errors.',
);
}
@override
String get name => 'publish';
@override
String get description {
return 'Publish the current package to pub.dev';
}
@override
String get invocation {
return '${runner.executableName} pub publish [--dry-run]';
}
@override
Future<FlutterCommandResult> runCommand() async {
final List<String> args = <String>[
...argResults.rest,
if (boolArg('dry-run')) '--dry-run',
if (boolArg('force')) '--force',
];
await pub.interactively(<String>['publish', ...args], stdio: globals.stdio);
return FlutterCommandResult.success();
}
}
class PackagesForwardCommand extends FlutterCommand {
PackagesForwardCommand(this._commandName, this._description, {bool requiresPubspec = false}) {
if (requiresPubspec) {
requiresPubspecYaml();
}
}
@override
ArgParser argParser = ArgParser.allowAnything();
final String _commandName;
final String _description;
......@@ -257,7 +223,6 @@ class PackagesForwardCommand extends FlutterCommand {
await pub.interactively(<String>[_commandName, ...argResults.rest], stdio: globals.stdio);
return FlutterCommandResult.success();
}
}
class PackagesPassthroughCommand extends FlutterCommand {
......
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