Skip to content

Add customizable category to pub Command #4611

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

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

dcharkes
Copy link
Contributor

@dcharkes dcharkes commented Jun 23, 2025

We'd like to add categories to the commands in dartdev:

$ dart --help
A command-line utility for Dart development.

Usage: dart <command|dart-file> [arguments]

Global options:
-v, --verbose               Show additional command output.
    --version               Print the Dart SDK version.
    --enable-analytics      Enable analytics.
    --disable-analytics     Disable analytics.
    --suppress-analytics    Disallow analytics for this `dart *` run without changing the analytics configuration.
-h, --help                  Print this usage information.

Available commands:

Dart SDK
  info       Show diagnostic information about the installed tooling.

Project
  analyze    Analyze Dart code in a directory.
  build      Build a Dart application including native assets.
  compile    Compile Dart to various formats.
  create     Create a new Dart project.
  doc        Generate API documentation for Dart projects.
  fix        Apply automated fixes to Dart source code.
  format     Idiomatically format Dart source code.
  pub        Work with packages.
  run        Run a Dart program.
  test       Run tests for a project.

Tools
  devtools   Open DevTools (optionally connecting to an existing application).

Run "dart help <command>" for more information about a command.
See https://dart.dev/tools/dart-tool for detailed documentation.

For that we need to be able to customize the categories getter.

Workaround without this PR is a src/ import with the following:

class PubEmbeddableCommand2 extends PubEmbeddableCommand {
  PubEmbeddableCommand2(super.isVerbose);

  @override
  String get category => 'Project';
}

I didn't find a lib/src/pub_embeddable_command_test.dart, where and how is this tested?

Context:

@dcharkes dcharkes requested a review from sigurdm June 23, 2025 09:56
@sigurdm
Copy link
Contributor

sigurdm commented Jun 23, 2025

It is tested (at least a bit) in test/embedding/embedding_test.dart

This I would possibly just test in dartdev testing (where it is actually used)

Isn't it easier to just hard-code the categories of subcommands inside dartdev? If we ever use the pubCommand from anywhere else, that might categorize differently...

@dcharkes
Copy link
Contributor Author

Isn't it easier to just hard-code the categories of subcommands inside dartdev?

The categories are hardcoded in dartdev. But pub is a different code base.

If we ever use the pubCommand from anywhere else, that might categorize differently...

That's why I made it a parameter!

@sigurdm
Copy link
Contributor

sigurdm commented Jun 23, 2025

Sorry - I think I expressed that poorly. I suggest having a centralized mapping of categories->commands, instead of having each command know its own category.

@dcharkes
Copy link
Contributor Author

Sorry - I think I expressed that poorly. I suggest having a centralized mapping of categories->commands, instead of having each command know its own category.

That is not how package:args works, we have to override the getter.

@sigurdm
Copy link
Contributor

sigurdm commented Jun 23, 2025

Ahh - I didn't realize this was a part of package:args - I thought you were doing something custom.
Sorry - never mind then. LGTM

@sigurdm sigurdm merged commit f6457fd into master Jun 23, 2025
44 of 45 checks passed
@sigurdm sigurdm deleted the pub-embeddable-command-category branch June 23, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants