-
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
Closed
+75
−1
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use cargo::ops; | ||
use cargo::util::{CliResult, Config}; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Options { | ||
flag_index: Option<String>, | ||
flag_verbose: u32, | ||
flag_quiet: Option<bool>, | ||
flag_color: Option<String>, | ||
flag_frozen: bool, | ||
flag_locked: bool, | ||
#[serde(rename = "flag_Z")] | ||
flag_z: Vec<String>, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Check if an api token exists locally and who it belongs to | ||
|
||
Usage: | ||
cargo whoami [options] [<token>] | ||
|
||
Options: | ||
-h, --help Print this message | ||
--index INDEX Registry index to search in | ||
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output) | ||
-q, --quiet No output printed to stdout | ||
--color WHEN Coloring: auto, always, never | ||
--frozen Require Cargo.lock and cache are up to date | ||
--locked Require Cargo.lock is up to date | ||
-Z FLAG ... Unstable (nightly-only) flags to Cargo | ||
|
||
"; | ||
|
||
pub fn execute(options: Options, config: &mut Config) -> CliResult { | ||
config.configure( | ||
options.flag_verbose, | ||
options.flag_quiet, | ||
&options.flag_color, | ||
options.flag_frozen, | ||
options.flag_locked, | ||
&options.flag_z, | ||
)?; | ||
|
||
let Options { | ||
flag_index: index, | ||
.. | ||
} = options; | ||
|
||
ops::registry_whoami(config, index)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, whilepublish
/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
, maybeAuthenticated as {}
orOperating 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
orid -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 aawk
-pass. That isand
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 ifstderr
is actually human-readable. One can extend that tostdout
and output an unformatted string if stdout is hooked up. If wonder if this is surprising behavior, though