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

Custom subcommand awareness #2187

Closed
alexcrichton opened this issue Nov 30, 2015 · 18 comments
Closed

Custom subcommand awareness #2187

alexcrichton opened this issue Nov 30, 2015 · 18 comments

Comments

@alexcrichton
Copy link
Member

Now that we've got cargo install it's quite easy to make new subcommands left and right. There's lots in the ecosystem already, but they're not necessarily always easy to discover! Similar to #1251, it'd be good if we had a better story for discovering custom subcommands in the wild via some means. Some questions that would be nice to answer are:

  • What are the most used subcommands?
  • What are the possible subcommands?
  • What subcommands are loosely on-track to become part of Cargo proper?

Some similar ideas to #1251 may lend themselves to here as well.

@achanda
Copy link
Contributor

achanda commented Nov 30, 2015

How about looking for cargo-* binaries in $PATH and the default cargo install location and displaying them on cargo -h?

@alexcrichton
Copy link
Member Author

Yeah that's certainly a possibility, right now cargo --list will do that as cargo -h is a "curated list" of subcommands (e.g. it doesn't even show all Cargo subcommands by default).

@Turbo87
Copy link
Member

Turbo87 commented Nov 30, 2015

I would suggest that every subcommand should use a certain keyword on crates.io. You could then filter for that keyword and see the most used subcommands.

@alilleybrinker
Copy link

If we're looking for cargo-* binaries in the system path, there's the question of whether we can reasonably assume those binaries are in fact Cargo sub commands, rather than unfortunately named and unrelated programs. Do we have any reason to believe such a problem may arise?

Marking a particular crates.io keyword as the signifier seriously limits the possibility of a mistake occurring (although someone could incorrectly assign the keyword to their project when it's not actually a cargo sub command project, so maybe some warning from crates.io may be warranted), but it also means that any cargo sub command that wants to be surfaced automatically by cargo has to be registered on crates.io, which some may find onerous.

@alexcrichton
Copy link
Member Author

I believe git takes a similar approach for poking for subcommands, but that's true that if cargo-foo is unrelated it could cause confusion if cargo foo is called or cargo --list is looked at.

I also think the keyword suggestion was simply for discovery, not that Cargo would check against crates.io to ensure that it's there or have it as a restriction. You'd just go brows everything with the cargo subcommand tag and in theory have a good idea about what all the subcommands are.

@kornelski
Copy link
Contributor

  1. For me the barrier was not even knowing that cargo subcommands are extensible. I assumed it only has built-in commands, like npm and composer do.
  2. Searching for cargo extensions on crates.io makes some sense, but I'm not sure if I'd go to search there. I think of crates.io as a source of libraries only, because I get rustc and cargo from rust-lang.org (and my second choice would be homebrew).
  3. I wanted an equivalent of npm install --save or composer require, but the command was called cargo add in cargo-edit package. Note complete lack of overlap between words I was looking for and the name it actually had.

@huonw
Copy link
Member

huonw commented Nov 30, 2015

How quickly can we work out what subcommands exist? E.g. could running cargo add somehow check the registry for packages with cargo-add binaries and print "maybe you want to install ..."?

This would preferably just use an existing registry, rather than update it, since that can be quite slow. But I guess we'd probably want to hit the network to determine sort order anyway.

@alexcrichton
Copy link
Member Author

@huonw I think basically as fast as cargo search, although perhaps with one less round trip to figure out what the registry URL is, so just a little faster than that in theory.

It's slow enough that I wouldn't want it to run on cargo foo where foo wasn't recognized, but I'd be fine running it via something like cargo search --subcommands or something like that.

@alexcrichton
Copy link
Member Author

Ah and as an example of speed, just run:

curl https://crates.io/api/v1/crates\?keyword\=subcommand

@nasa42
Copy link
Member

nasa42 commented Dec 1, 2015

There is also http://libs.rs/cargo-subcommands/ (I maintain the site).

@kornelski
Copy link
Contributor

cargo --list could have a hint such as "Install more commands from: https://crates.io/search?q=subcommand"

@kbknapp
Copy link

kbknapp commented Dec 2, 2015

There is also cargo-extras which is a meta package for installing all the popular commands at once.

IMO there just needs to be a better way discover, search for, and install subcommands.

@g-k
Copy link

g-k commented Mar 11, 2016

  • What subcommands are loosely on-track to become part of Cargo proper?

Like cargo-extras, a semiofficial cargo-nursery org or rust-lang-nursery/cargo-subcommands repo could convey social proof and make discovery a bit easier.

@deepak
Copy link

deepak commented Apr 13, 2016

+1 can have a section on the guide as well

also, a guide on how to write a cargo subcommand is missing

@drusellers
Copy link

cargo --list is nice but I'd love to see something that has a bit more detail - when possible. My current cargo --list looks like

drusellers@Drus-MBP-2 ~/dev/beta/beta-cli (master)
$ cargo --list
Installed Commands:
    add
    bench
    build
    bump
    check
    clean
    clippy
    doc
    fetch
    fmt
    generate-lockfile
    git-checkout
    help
    init
    install
    list
    locate-project
    login
    metadata
    modules
    new
    outdated
    owner
    package
    pkgid
    publish
    read-manifest
    rm
    run
    rustc
    rustdoc
    search
    test
    uninstall
    update
    verify-project
    version
    yank

I would one like to see the official partitioned from the add ons. like so

drusellers@Drus-MBP-2 ~/dev/beta/beta-cli (master)
$ cargo --list
All Commands:
    Core Commands:
        bench
        build
        clean
        doc
        fetch
        generate-lockfile
        git-checkout
        help
        init
        install
        locate-project
        login
        metadata
        new
        owner
        package
        pkgid
        publish
        read-manifest
        run
        rustc
        rustdoc
        search
        test
        uninstall
        update
        verify-project
        version
        yank

    Added On Commands:
        add
        bump
        check
        clippy
        fmt
        list
        modules
        outdated
        rm

Then if possible, I'd love to see if its possible to provide the help text. Now I know the default help text comes from clap or similar - so sub commands would have to provide some integration to support this next idea. But if subcommands had a subcommand like cargo-help that could feed the following data back to cargo that would be nifty.

    Added On Commands:
        add - what this command does
        bump - what this command does

The goal is to remind my old brain why I installed this add on.

@carols10cents
Copy link
Member

There are a lot of different ideas in this issue; please open new issues for them if you're still interested.

As far as the main issue, I think this has been addressed by categories on crates.io which have descriptions and are a bit easier to discover than keywords. Here's the category for cargo plugins: https://crates.io/categories/development-tools::cargo-plugins

@MondoGao
Copy link

@drusellers Do we have a new issue about your proposal? I still get the same output with -list and your format seems much better.

@drusellers
Copy link

@MondoGao I have not. Please feel free to.

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

No branches or pull requests