Skip to content

Commit 01e079e

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
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>
1 parent 4bde1f1 commit 01e079e

5 files changed

Lines changed: 148 additions & 0 deletions

File tree

pkg/dartdev/lib/dartdev.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:cli_util/cli_logging.dart';
88

99
import 'src/commands/create.dart';
1010
import 'src/commands/format.dart';
11+
import 'src/commands/pub.dart';
1112
import 'src/core.dart';
1213

1314
class DartdevRunner<int> extends CommandRunner {
@@ -22,6 +23,7 @@ class DartdevRunner<int> extends CommandRunner {
2223

2324
addCommand(CreateCommand(verbose: verbose));
2425
addCommand(FormatCommand(verbose: verbose));
26+
addCommand(PubCommand(verbose: verbose));
2527
}
2628

2729
@override
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:pub/src/command/cache.dart';
8+
import 'package:pub/src/command/deps.dart';
9+
import 'package:pub/src/command/downgrade.dart';
10+
import 'package:pub/src/command/get.dart';
11+
import 'package:pub/src/command/global.dart';
12+
import 'package:pub/src/command/lish.dart';
13+
import 'package:pub/src/command/list_package_dirs.dart';
14+
import 'package:pub/src/command/logout.dart';
15+
import 'package:pub/src/command/run.dart';
16+
import 'package:pub/src/command/serve.dart';
17+
import 'package:pub/src/command/upgrade.dart';
18+
import 'package:pub/src/command/uploader.dart';
19+
import 'package:pub/src/command_runner.dart';
20+
21+
import '../core.dart';
22+
import '../utils.dart';
23+
24+
class PubCommand extends DartdevCommand<int> {
25+
var pubCommandRunner = PubCommandRunner();
26+
27+
PubCommand({bool verbose = false})
28+
: super('pub', 'Pub is a package manager for Dart.') {
29+
argParser.addFlag('version', negatable: false, help: 'Print pub version.');
30+
argParser.addFlag('trace',
31+
help: 'Print debugging information when an error occurs.');
32+
argParser
33+
.addOption('verbosity', help: 'Control output verbosity.', allowed: [
34+
'error',
35+
'warning',
36+
'normal',
37+
'io',
38+
'solver',
39+
'all'
40+
], allowedHelp: {
41+
'error': 'Show only errors.',
42+
'warning': 'Show only errors and warnings.',
43+
'normal': 'Show errors, warnings, and user messages.',
44+
'io': 'Also show IO operations.',
45+
'solver': 'Show steps during version resolution.',
46+
'all': 'Show all output including internal tracing messages.'
47+
});
48+
argParser.addFlag('verbose',
49+
abbr: 'v', negatable: false, help: 'Shortcut for "--verbosity=all".');
50+
argParser.addFlag('with-prejudice',
51+
hide: !isAprilFools,
52+
negatable: false,
53+
help: 'Execute commands with prejudice.');
54+
argParser.addFlag('sparkle',
55+
hide: !isAprilFools,
56+
negatable: false,
57+
help: 'A more sparkly experience.');
58+
59+
addSubcommand(CacheCommand());
60+
addSubcommand(DepsCommand());
61+
addSubcommand(DowngradeCommand());
62+
addSubcommand(GlobalCommand());
63+
addSubcommand(GetCommand());
64+
addSubcommand(ListPackageDirsCommand());
65+
addSubcommand(LishCommand());
66+
addSubcommand(RunCommand());
67+
addSubcommand(ServeCommand());
68+
addSubcommand(UpgradeCommand());
69+
addSubcommand(UploaderCommand());
70+
addSubcommand(LogoutCommand());
71+
}
72+
73+
@override
74+
FutureOr<int> run() async {
75+
await pubCommandRunner.run(argResults.arguments);
76+
return 0;
77+
}
78+
}

pkg/dartdev/lib/src/utils.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ typedef void VoidFunction();
2525

2626
final NumberFormat _numberFormat = NumberFormat.decimalPattern();
2727

28+
/// Whether today is April Fools' day.
29+
bool get isAprilFools {
30+
var date = DateTime.now();
31+
return date.month == 4 && date.day == 1;
32+
}
33+
2834
/// Convert the given number to a string using the current locale.
2935
String formatNumber(int i) => _numberFormat.format(i);
3036

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test/test.dart';
6+
7+
import '../utils.dart';
8+
9+
void main() {
10+
group('pub', pub);
11+
}
12+
13+
void pub() {
14+
TestProject p;
15+
16+
tearDown(() => p?.dispose());
17+
18+
test('implicit --help', () {
19+
p = project();
20+
var result = p.runSync('pub');
21+
expect(result.exitCode, 64);
22+
expect(result.stdout, isEmpty);
23+
expect(
24+
result.stderr, contains('Usage: dartdev pub <subcommand> [arguments]'));
25+
expect(result.stderr,
26+
contains('Print debugging information when an error occurs.'));
27+
});
28+
29+
test('--help', () {
30+
p = project();
31+
var result = p.runSync('pub', ['--help']);
32+
33+
expect(result.exitCode, 0);
34+
expect(result.stderr, isEmpty);
35+
expect(result.stdout, contains('Pub is a package manager for Dart.'));
36+
expect(
37+
result.stdout, contains('Usage: dartdev pub <subcommand> [arguments]'));
38+
expect(result.stdout,
39+
contains('Print debugging information when an error occurs.'));
40+
});
41+
42+
test('success', () {
43+
p = project(mainSrc: 'int get foo => 1;\n');
44+
var result = p.runSync('pub', ['deps']);
45+
expect(result.exitCode, 1);
46+
expect(
47+
result.stderr,
48+
startsWith(
49+
'''No pubspec.lock file found, please run "pub get" first.'''));
50+
expect(result.stdout, isEmpty);
51+
});
52+
53+
test('failure', () {
54+
p = project(mainSrc: 'int get foo => 1;\n');
55+
var result = p.runSync('pub', ['deps', '--foo']);
56+
expect(result.exitCode, 64);
57+
expect(result.stderr, startsWith('Could not find an option named "foo".'));
58+
expect(result.stdout, isEmpty);
59+
});
60+
}

pkg/dartdev/test/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import 'package:test/test.dart';
77
import 'commands/create_test.dart' as create;
88
import 'commands/flag_test.dart' as flag;
99
import 'commands/format_test.dart' as format;
10+
import 'commands/pub_test.dart' as pub;
1011
import 'utils_test.dart' as utils;
1112

1213
main() {
1314
group('dartdev', () {
1415
create.main();
1516
flag.main();
1617
format.main();
18+
pub.main();
1719
utils.main();
1820
});
1921
}

0 commit comments

Comments
 (0)