-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add a whoami
command to display the logged in user
#4625
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for the PR! This sounds like a good idea to me, so I'm fine adding it. I think it's ok to skip tests as this does indeed seem like it'd be hard to test, but I imagine you've verified it locally :) @rust-lang/cargo, thoughts on this new subcommand? |
@alexcrichton Sweet! I did test it locally, with both scenarios. I saw there were some tests that mocked network responses like the search tests, but I couldn't get those to work for the |
let (mut registry, _) = registry(config, token.clone(), index)?; | ||
|
||
match registry.whoami() { | ||
Ok(user) => config.shell().status("Whoami", format!("Currently logged in as `{}`", user.login))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this wording is optimal. "Currently logged in as", given to a web-accustomed audience, sounds like the status of a temporary session. We could also be more clear about where this user
is actually used.
FWIW "Crates will be published/yanked by user `{}`"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukaslueg I get where you're coming from, and normally I'd agree. Two things are hanging me up though. The first is that users already establish local credentials by running cargo login
(normally), so there's already some precedent there. Additionally, while publish
/yank
are probably the two most common commands, there's certainly more to do that requires authentication.
If you wanted to move away from logged in
, maybe Authenticated as {}
or Operating as {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest mirroring what whoami
or id -un
does and just print out the username, with no further formatting. This has the added benefit that the command can be used in scripts more easily, without having to do a awk
-pass. That is
$ cargo whoami
leeroyjenkins
and
$ cargo whoami
[some TokenMissing-message to stderr]
$ echo $?
1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that as well while implementing this. The main reason I didn't is because it doesn't match how the rest of cargo generally outputs info to STDOUT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#4646 comes with a small change in config.shell()
to determine if stderr
is actually human-readable. One can extend that to stdout
and output an unformatted string if stdout is hooked up. If wonder if this is surprising behavior, though
We discussed this PR during the cargo team meeting today. While we don't have anything particular against including a That is, we'd strongly prefer all new subcommands to be either:
We also discussed improving the discoverability of plugins by having cargo suggest that you install the plugin if you use a command that exists as a plugin, e.g:
@joshtriplett opened an issue to discuss this discoverability feature at #4682. Thanks for the PR though! If you feel up to it, please do publish a |
Thanks @withoutboats for the breakdown. Once I find some time, I'll definitely work on making this a plugin. |
This adds a new command to cargo called
whoami
, which will display thelogin
name of the user that belongs to the saved credential.I realize I did this without making an issue first to discuss it—sorry about that. I'm also aware that cargo has a built in plugin system, but a
whoami
command felt like it should be in cargo itself. If y'all feel differently, feel free to close this PR and I'll create a cargo plugin.I also attempted to write some integration tests, but wasn't able to successfully. It seems like most commands are covered by tests but I might have been searching wrong. If tests are desired, let me know and I can take another stab at it.
Finally, if there is anything I should change, add, remove, etc, please let me know and I'll be happy to do that!