The initial dartdev pub * command - pass on all arguments from the 'dartdev pub *' invocation directly to 'pub *'.

Change-Id: Ife14cfad7634c03c41b19db68f2cb6c4b26be0cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134600
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
Jaime Wren 2020-02-13 20:43:38 +00:00 committed by commit-bot@chromium.org
parent 4bde1f1851
commit 01e079eff1
5 changed files with 148 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import 'package:cli_util/cli_logging.dart';
import 'src/commands/create.dart';
import 'src/commands/format.dart';
import 'src/commands/pub.dart';
import 'src/core.dart';
class DartdevRunner<int> extends CommandRunner {
@ -22,6 +23,7 @@ class DartdevRunner<int> extends CommandRunner {
addCommand(CreateCommand(verbose: verbose));
addCommand(FormatCommand(verbose: verbose));
addCommand(PubCommand(verbose: verbose));
}
@override

View file

@ -0,0 +1,78 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:pub/src/command/cache.dart';
import 'package:pub/src/command/deps.dart';
import 'package:pub/src/command/downgrade.dart';
import 'package:pub/src/command/get.dart';
import 'package:pub/src/command/global.dart';
import 'package:pub/src/command/lish.dart';
import 'package:pub/src/command/list_package_dirs.dart';
import 'package:pub/src/command/logout.dart';
import 'package:pub/src/command/run.dart';
import 'package:pub/src/command/serve.dart';
import 'package:pub/src/command/upgrade.dart';
import 'package:pub/src/command/uploader.dart';
import 'package:pub/src/command_runner.dart';
import '../core.dart';
import '../utils.dart';
class PubCommand extends DartdevCommand<int> {
var pubCommandRunner = PubCommandRunner();
PubCommand({bool verbose = false})
: super('pub', 'Pub is a package manager for Dart.') {
argParser.addFlag('version', negatable: false, help: 'Print pub version.');
argParser.addFlag('trace',
help: 'Print debugging information when an error occurs.');
argParser
.addOption('verbosity', help: 'Control output verbosity.', allowed: [
'error',
'warning',
'normal',
'io',
'solver',
'all'
], allowedHelp: {
'error': 'Show only errors.',
'warning': 'Show only errors and warnings.',
'normal': 'Show errors, warnings, and user messages.',
'io': 'Also show IO operations.',
'solver': 'Show steps during version resolution.',
'all': 'Show all output including internal tracing messages.'
});
argParser.addFlag('verbose',
abbr: 'v', negatable: false, help: 'Shortcut for "--verbosity=all".');
argParser.addFlag('with-prejudice',
hide: !isAprilFools,
negatable: false,
help: 'Execute commands with prejudice.');
argParser.addFlag('sparkle',
hide: !isAprilFools,
negatable: false,
help: 'A more sparkly experience.');
addSubcommand(CacheCommand());
addSubcommand(DepsCommand());
addSubcommand(DowngradeCommand());
addSubcommand(GlobalCommand());
addSubcommand(GetCommand());
addSubcommand(ListPackageDirsCommand());
addSubcommand(LishCommand());
addSubcommand(RunCommand());
addSubcommand(ServeCommand());
addSubcommand(UpgradeCommand());
addSubcommand(UploaderCommand());
addSubcommand(LogoutCommand());
}
@override
FutureOr<int> run() async {
await pubCommandRunner.run(argResults.arguments);
return 0;
}
}

View file

@ -25,6 +25,12 @@ typedef void VoidFunction();
final NumberFormat _numberFormat = NumberFormat.decimalPattern();
/// Whether today is April Fools' day.
bool get isAprilFools {
var date = DateTime.now();
return date.month == 4 && date.day == 1;
}
/// Convert the given number to a string using the current locale.
String formatNumber(int i) => _numberFormat.format(i);

View file

@ -0,0 +1,60 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:test/test.dart';
import '../utils.dart';
void main() {
group('pub', pub);
}
void pub() {
TestProject p;
tearDown(() => p?.dispose());
test('implicit --help', () {
p = project();
var result = p.runSync('pub');
expect(result.exitCode, 64);
expect(result.stdout, isEmpty);
expect(
result.stderr, contains('Usage: dartdev pub <subcommand> [arguments]'));
expect(result.stderr,
contains('Print debugging information when an error occurs.'));
});
test('--help', () {
p = project();
var result = p.runSync('pub', ['--help']);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, contains('Pub is a package manager for Dart.'));
expect(
result.stdout, contains('Usage: dartdev pub <subcommand> [arguments]'));
expect(result.stdout,
contains('Print debugging information when an error occurs.'));
});
test('success', () {
p = project(mainSrc: 'int get foo => 1;\n');
var result = p.runSync('pub', ['deps']);
expect(result.exitCode, 1);
expect(
result.stderr,
startsWith(
'''No pubspec.lock file found, please run "pub get" first.'''));
expect(result.stdout, isEmpty);
});
test('failure', () {
p = project(mainSrc: 'int get foo => 1;\n');
var result = p.runSync('pub', ['deps', '--foo']);
expect(result.exitCode, 64);
expect(result.stderr, startsWith('Could not find an option named "foo".'));
expect(result.stdout, isEmpty);
});
}

View file

@ -7,6 +7,7 @@ import 'package:test/test.dart';
import 'commands/create_test.dart' as create;
import 'commands/flag_test.dart' as flag;
import 'commands/format_test.dart' as format;
import 'commands/pub_test.dart' as pub;
import 'utils_test.dart' as utils;
main() {
@ -14,6 +15,7 @@ main() {
create.main();
flag.main();
format.main();
pub.main();
utils.main();
});
}