@@ -87,21 +87,18 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport
87
87
inputSchema: Schema .object (
88
88
properties: {
89
89
ParameterNames .command: Schema .string (
90
- title: 'The pub command to run.' ,
91
- description:
92
- 'Currently only ${SupportedPubCommand .listAll } are supported.' ,
90
+ title: 'The pub subcommand to run.' ,
91
+ enumValues: SupportedPubCommand .values
92
+ .map <String >((e) => e.name)
93
+ .toList (),
94
+ description: SupportedPubCommand .commandDescriptions,
93
95
),
94
96
ParameterNames .packageNames: Schema .list (
95
97
title: 'The package names to run the command for.' ,
96
98
description:
97
99
'This is required for the '
98
100
'${SupportedPubCommand .listAllThatRequirePackageName } commands. ' ,
99
- items: Schema .string (
100
- title: 'A package to run the command for.' ,
101
- description:
102
- 'When used with "add", prefix with "dev:" to add the package '
103
- 'as a dev dependency.' ,
104
- ),
101
+ items: Schema .string (title: 'A package to run the command for.' ),
105
102
),
106
103
ParameterNames .roots: rootsSchema (),
107
104
},
@@ -112,22 +109,49 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport
112
109
113
110
/// The set of supported `dart pub` subcommands.
114
111
enum SupportedPubCommand {
115
- // This is supported in a simplified form: `dart pub add <package-name>`.
116
- // TODO(https://github.com/dart-lang/ai/issues/77): add support for adding
117
- // dev dependencies.
118
- add (requiresPackageNames: true ),
119
-
120
- get ,
112
+ add (
113
+ requiresPackageNames: true ,
114
+ description: '''Add package dependencies.
115
+ - To add a package normally (typical): "pkg_name"
116
+ - Git reference: "pkg_name:{git:{url: https://github.com/pkg_name/pkg_name.git, ref: branch, path: subdir}}"
117
+ - ref and path are optional.
118
+ - From local path: "pkg_name:{path: ../pkg_name}"
119
+ - Dev Dependency: "dev:pkg_name"
120
+ - Dependency override: "override:pkg_name:1.0.0"
121
+ ''' ,
122
+ ),
123
+
124
+ deps (description: 'Print the dependency tree of the current package.' ),
125
+
126
+ get (
127
+ description: "Fetch the current package's dependencies and install them." ,
128
+ ),
129
+
130
+ outdated (
131
+ description: 'Analyze dependencies to find which ones can be upgraded.' ,
132
+ ),
121
133
122
134
// This is supported in a simplified form: `dart pub remove <package-name>`.
123
- remove (requiresPackageNames: true ),
135
+ remove (
136
+ requiresPackageNames: true ,
137
+ description: 'Removes specified dependencies from `pubspec.yaml`.' ,
138
+ ),
124
139
125
- upgrade;
140
+ upgrade (
141
+ description:
142
+ "Upgrade the current package's dependencies to latest versions." ,
143
+ );
126
144
127
- const SupportedPubCommand ({this .requiresPackageNames = false });
145
+ const SupportedPubCommand ({
146
+ this .requiresPackageNames = false ,
147
+ required this .description,
148
+ });
128
149
129
150
final bool requiresPackageNames;
130
151
152
+ /// The description to use in the subcommand help.
153
+ final String description;
154
+
131
155
static SupportedPubCommand ? fromName (String name) {
132
156
for (final command in SupportedPubCommand .values) {
133
157
if (command.name == name) {
@@ -147,6 +171,22 @@ enum SupportedPubCommand {
147
171
);
148
172
}
149
173
174
+ static String get commandDescriptions {
175
+ return 'Available subcommands:\n ${_getDescriptions (values )}' ;
176
+ }
177
+
178
+ static String _getDescriptions (Iterable <SupportedPubCommand > commands) {
179
+ final buffer = StringBuffer ();
180
+ for (final command in commands) {
181
+ final commandName = command.name;
182
+ final description = command.description;
183
+ if (description.isNotEmpty) {
184
+ buffer.writeln ('- `$commandName `: $description ' );
185
+ }
186
+ }
187
+ return buffer.toString ();
188
+ }
189
+
150
190
static String _writeCommandsAsList (List <SupportedPubCommand > commands) {
151
191
final buffer = StringBuffer ();
152
192
for (var i = 0 ; i < commands.length; i++ ) {
0 commit comments