Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to get help for pub subcommands with dart pub #42965

Closed
mit-mit opened this issue Aug 6, 2020 · 13 comments
Closed

No way to get help for pub subcommands with dart pub #42965

mit-mit opened this issue Aug 6, 2020 · 13 comments
Assignees
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. P2 A bug or feature request we're likely to work on

Comments

@mit-mit
Copy link
Member

mit-mit commented Aug 6, 2020

Pub has many sub-commands. Getting help for this is a fairly common use case. However. dart help pub publish fails:

mit-macbookpro4:~ mit$ dart help pub publish
Command "dart pub" does not expect a subcommand.

Usage: dart pub [arguments]

Note that this does seem to work for other commands, e.g. compile:

mit-macbookpro4:~ mit$ dart help compile exe
Compile Dart to a self-contained executable

Usage: dart compile exe [arguments] <dart entry point>
@mit-mit
Copy link
Member Author

mit-mit commented Aug 6, 2020

cc @jwren @jonasfj

@mit-mit mit-mit added the area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. label Aug 6, 2020
@jonasfj
Copy link
Member

jonasfj commented Aug 7, 2020

dart pub help publish is likely to work. We could do a work around for this. Otherwise, I would expect this to resolve if we manage to get pub embedded in dartdev.

@mit-mit
Copy link
Member Author

mit-mit commented Aug 13, 2020

Note that this does work:

mit-macbookpro4:flutter mit$ dart help compile exe
Compile Dart to a self-contained executable

Usage: dart compile exe [arguments] <dart entry point>
-h, --help                          Print this usage information.
-o, --output                        Write the output to <file name>.
                                    This can be an absolute or reletive path.
-D, --define=<key=value>            Set values of environment variables. To specify multiple variables, use multiple options or use commas to separate key-value pairs.
                                    E.g.: dart compile exe -Da=1,b=2 main.dart
    --enable-asserts                Enable assert statements.
-p, --packages=<path>               Get package locations from the specified file instead of .packages. <path> can be relative or absolute.
                                    E.g.: dart compile exe --packages=/tmp/pkgs main.dart
-S, --save-debugging-info=<path>    Remove debugging information from the output and save it separately to the specified file. <path> can be relative or absolute.

@mit-mit
Copy link
Member Author

mit-mit commented Aug 13, 2020

This is caused by the argument parsers for some older commands (like pub) being shallow wrappers in dart CLI that call out to the existing commands. Over time as we discontinue the older commands, we can move all of the command and argument parsing into the dart CLI.

Also, you can use dart pub publish --help. Would be good to investigate if we can generally support turning dart help foo bar into dart foo bar --help.

@mit-mit mit-mit added this to the September Release 2020 milestone Aug 13, 2020
@mit-mit mit-mit added the P2 A bug or feature request we're likely to work on label Aug 13, 2020
@jwren

This comment has been minimized.

@mit-mit

This comment has been minimized.

@jwren

This comment has been minimized.

@devoncarew
Copy link
Member

I believe a solution for this would be to do some light parsing of the command line for the pub subcommand, to convert:

dart help pub publish

(which currently fails), to:

dart pub publish -h

which will succeed.

We'd need to be careful with that parsing and re-writing to ensure that we're correct in various cases; hopefully we can cover that w/ good unit tests.

I don't think this is critical for this milestone however; it's currently a P2 - we may consider moving it out of the milestone as we get closer to the release.

@jwren
Copy link
Member

jwren commented Aug 18, 2020

@devoncarew -- yes, thank you for articulating on the bug. I am working on this issue now. With the exception of a Dart VM issue, this is the last dart-cli bug labeled with the September milestone.

@jwren
Copy link
Member

jwren commented Aug 18, 2020

@devoncarew @mit-mit

A call to dart help pub publish doesn't invoke any code (such as printUsage in pub.dart)

To re-order the commands, we'd have to intercept modify the runCommand (in dartdev.dart) to match when the user has [..., help, pub, ...] in their arguments. However, even when such a match has been made, there is no way to then have the arguments re-ordered or re-parsed with the current args library: newArgResults is hidden when src/arg_results.dart is exported.

Unfortunately, with the architecture of the args package the most robust way to implement this would be to copy the pub argument parser over like we have done for test. Given this, how important is this for the September release schedule?

@devoncarew
Copy link
Member

A call to dart help pub publish doesn't invoke any code (such as printUsage in pub.dart)

To re-order the commands, we'd have to intercept modify the runCommand (in dartdev.dart) to match when the user has [..., help, pub, ...] in their arguments. However, even when such a match has been made, there is no way to then have the arguments re-ordered or re-parsed with the current args library...

Yes, I think the CommandRunner doesn't support re-writing / re-parsing args. Its a specialized use case (but important when you need it).

Have you considered doing the re-write before we pass the list of args to CommandRunner.run()? That would be on or around https://github.com/dart-lang/sdk/blob/master/pkg/dartdev/lib/dartdev.dart#L122. This is were things get tricky - you have to be careful about how you identify something like help pub publish, so you don't mis-identify other invocations.

@jonasfj
Copy link
Member

jonasfj commented Aug 18, 2020

We have work ongoing in dart-lang/pub#2622 to facilitate embedding pub in dartdev, that would alleviate these issues.

@jwren
Copy link
Member

jwren commented Aug 19, 2020

PR out at https://dart-review.googlesource.com/c/sdk/+/159341. @jonasfj - if/when embedding is done of pub into dartdev directly, the tests should remain, but the argument parsing in lib/dartdev.dart should be removed.

dart-bot pushed a commit that referenced this issue Aug 25, 2020
Bug: #42965
Change-Id: Id2446b88fb983607f841c2fda81434087dc71d62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159341
Commit-Queue: Jaime Wren <jwren@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
@jwren jwren closed this as completed Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants