diff --git a/lib/pub.dart b/lib/pub.dart index d7b5653e49..12f364cb07 100644 --- a/lib/pub.dart +++ b/lib/pub.dart @@ -8,6 +8,7 @@ import 'src/entrypoint.dart'; import 'src/exceptions.dart'; import 'src/http.dart'; import 'src/pub_embeddable_command.dart'; +import 'src/source/git.dart'; import 'src/system_cache.dart'; export 'src/executable.dart' @@ -67,3 +68,39 @@ class ResolutionFailedException implements Exception { String message; ResolutionFailedException._(this.message); } + +/// Given a Git repo that contains a pub package, gets the name of the pub +/// package. +/// +/// Will download the repo to the system cache under the assumption that the +/// package will be downloaded afterwards. +/// +/// [url] points to the git repository. If it is a relative url, it is resolved +/// as a file url relative to the path [relativeTo]. +/// +/// [ref] is the commit, tag, or branch name where the package should be looked +/// up when fetching the name. If omitted, 'HEAD' is used. +/// +/// [tagPattern] is a string containing `'{{version}}'` as a substring, the +/// latest tag matching the pattern will be used for fetching the name. +/// +/// Only one of [ref] and [tagPattern] can be used. +/// +/// If [isOffline], only the already cached versions of the repo is used. +Future getPackageNameFromGitRepo( + String url, { + String? ref, + String? path, + String? tagPattern, + String? relativeTo, + bool isOffline = false, +}) async { + return await GitSource.instance.getPackageNameFromRepo( + url, + ref, + path, + SystemCache(isOffline: isOffline), + relativeTo: relativeTo, + tagPattern: tagPattern, + ); +} diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index 7c6c701dc3..273c66f906 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart @@ -167,7 +167,6 @@ For example (follow the same format including spaces): defaultsTo: true, help: 'Also update dependencies in `example/` after modifying pubspec.yaml in the root package (if it exists).', - hide: true, ); } diff --git a/lib/src/command/downgrade.dart b/lib/src/command/downgrade.dart index 1bdd09230a..d9991381d8 100644 --- a/lib/src/command/downgrade.dart +++ b/lib/src/command/downgrade.dart @@ -48,7 +48,6 @@ class DowngradeCommand extends PubCommand { 'example', defaultsTo: true, help: 'Also run in `example/` (if it exists).', - hide: true, ); argParser.addOption( diff --git a/lib/src/command/get.dart b/lib/src/command/get.dart index 4e522c05e7..dd3bbdc15b 100644 --- a/lib/src/command/get.dart +++ b/lib/src/command/get.dart @@ -56,7 +56,6 @@ class GetCommand extends PubCommand { 'example', defaultsTo: true, help: 'Also run in `example/` (if it exists).', - hide: true, ); argParser.addOption( diff --git a/lib/src/command/login.dart b/lib/src/command/login.dart index 04e765b7dc..0a505b660b 100644 --- a/lib/src/command/login.dart +++ b/lib/src/command/login.dart @@ -64,7 +64,9 @@ class LoginCommand extends PubCommand { try { switch (json.decode(userInfoRequest.body)) { case {'name': final String? name, 'email': final String email}: - return _UserInfo(name, email); + return _UserInfo(name: name, email: email); + case {'email': final String email}: + return _UserInfo(name: null, email: email); default: log.fine( 'Bad response from $userInfoEndpoint: ${userInfoRequest.body}', @@ -84,7 +86,7 @@ class LoginCommand extends PubCommand { class _UserInfo { final String? name; final String email; - _UserInfo(this.name, this.email); + _UserInfo({required this.name, required this.email}); @override String toString() => ['<$email>', name ?? ''].join(' '); } diff --git a/lib/src/command/remove.dart b/lib/src/command/remove.dart index 32e75906b3..7f4ac2af0e 100644 --- a/lib/src/command/remove.dart +++ b/lib/src/command/remove.dart @@ -59,7 +59,6 @@ To remove a dependency override of a package prefix the package name with 'example', defaultsTo: true, help: 'Also update dependencies in `example/` (if it exists).', - hide: true, ); argParser.addOption( diff --git a/lib/src/command/upgrade.dart b/lib/src/command/upgrade.dart index a817ff41e0..44365e870a 100644 --- a/lib/src/command/upgrade.dart +++ b/lib/src/command/upgrade.dart @@ -89,7 +89,6 @@ class UpgradeCommand extends PubCommand { 'example', defaultsTo: true, help: 'Also run in `example/` (if it exists).', - hide: true, ); argParser.addOption( diff --git a/lib/src/source/git.dart b/lib/src/source/git.dart index 7f03059274..9087944659 100644 --- a/lib/src/source/git.dart +++ b/lib/src/source/git.dart @@ -290,7 +290,7 @@ class GitSource extends CachedSource { String? ref, String? path, SystemCache cache, { - required String relativeTo, + required String? relativeTo, required String? tagPattern, }) async { assert( diff --git a/test/testdata/goldens/help_test/pub add --help.txt b/test/testdata/goldens/help_test/pub add --help.txt index f6f73fb96e..4aca35f98c 100644 --- a/test/testdata/goldens/help_test/pub add --help.txt +++ b/test/testdata/goldens/help_test/pub add --help.txt @@ -43,6 +43,8 @@ Usage: pub add [options] [
:][:descriptor] [
:] Run this in the directory . + --[no-]example Also update dependencies in `example/` after modifying pubspec.yaml in the root package (if it exists). + (defaults to on) Run "pub help" to see global options. See https://dart.dev/tools/pub/cmd/pub-add for detailed documentation. diff --git a/test/testdata/goldens/help_test/pub downgrade --help.txt b/test/testdata/goldens/help_test/pub downgrade --help.txt index a97139569a..0b86d3ed4d 100644 --- a/test/testdata/goldens/help_test/pub downgrade --help.txt +++ b/test/testdata/goldens/help_test/pub downgrade --help.txt @@ -10,6 +10,8 @@ Usage: pub downgrade [dependencies...] -h, --help Print this usage information. --[no-]offline Use cached packages instead of accessing the network. -n, --dry-run Report what dependencies would change but don't change any. + --[no-]example Also run in `example/` (if it exists). + (defaults to on) -C, --directory= Run this in the directory . --tighten Updates lower bounds in pubspec.yaml to match the resolved version. diff --git a/test/testdata/goldens/help_test/pub get --help.txt b/test/testdata/goldens/help_test/pub get --help.txt index dd5aaf5045..3c68ab101d 100644 --- a/test/testdata/goldens/help_test/pub get --help.txt +++ b/test/testdata/goldens/help_test/pub get --help.txt @@ -12,6 +12,8 @@ Usage: pub get has changed. Useful for CI or deploying to production. --[no-]precompile Build executables in immediate dependencies. + --[no-]example Also run in `example/` (if it exists). + (defaults to on) -C, --directory= Run this in the directory . Run "pub help" to see global options. diff --git a/test/testdata/goldens/help_test/pub remove --help.txt b/test/testdata/goldens/help_test/pub remove --help.txt index 2032abfa18..34e1463fcf 100644 --- a/test/testdata/goldens/help_test/pub remove --help.txt +++ b/test/testdata/goldens/help_test/pub remove --help.txt @@ -16,6 +16,8 @@ Usage: pub remove [...] --[no-]offline Use cached packages instead of accessing the network. -n, --dry-run Report what dependencies would change but don't change any. --[no-]precompile Precompile executables in immediate dependencies. + --[no-]example Also update dependencies in `example/` (if it exists). + (defaults to on) -C, --directory= Run this in the directory . Run "pub help" to see global options. diff --git a/test/testdata/goldens/help_test/pub upgrade --help.txt b/test/testdata/goldens/help_test/pub upgrade --help.txt index ade5a8dc4e..90030c7ca6 100644 --- a/test/testdata/goldens/help_test/pub upgrade --help.txt +++ b/test/testdata/goldens/help_test/pub upgrade --help.txt @@ -12,6 +12,8 @@ Usage: pub upgrade [dependencies...] --tighten Updates lower bounds in pubspec.yaml to match the resolved version. --unlock-transitive Also upgrades the transitive dependencies of the listed [dependencies] --major-versions Upgrades packages to their latest resolvable versions, and updates pubspec.yaml. + --[no-]example Also run in `example/` (if it exists). + (defaults to on) -C, --directory= Run this in the directory . Run "pub help" to see global options.