-
Notifications
You must be signed in to change notification settings - Fork 664
Identity command improvements #11
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
Conversation
1745129 to
663c45a
Compare
gefjon
left a comment
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've read and written "identity" so many times that it no longer looks like a word.
crates/cli/src/config.rs
Outdated
| let configs = self.identity_configs_mut(); | ||
| for config in configs.iter_mut() { | ||
| if config.identity == identity { | ||
| config.nickname = Some(name); |
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.
Should this warn if the identity already has a nickname?
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.
Good suggestion. Added
crates/cli/src/config.rs
Outdated
|
|
||
| pub fn set_identity_nickname(&mut self, identity: String, name: String) -> Result<(), anyhow::Error> { | ||
| let configs = self.identity_configs_mut(); | ||
| for config in configs.iter_mut() { |
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.
You can probably rewrite your for loop here to use Iterator::find, which might look like:
let config = configs.iter_mut()
.find(|config| config.identity == identity) // Returns Option<&mut WhateverTypeConfigsAre>
.ok_or_else(|| anyhow::anyhow!("Identity {} not found", identity) // Converts Option to Result; closure to avoid formatting unless necessary
?; // Bails if not found
config.nickname = Some(name);
Ok(())Whether you think that's more clear is up to you.
crates/cli/src/config.rs
Outdated
| &self | ||
| .identity_configs() | ||
| .iter() | ||
| .find(|c| c.identity == identity_or_name.clone()) |
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 suspect this clone is unnecessary; you might be able to convince rustc by writing &c.identity == &identity_or_name. In my experience, getting the borrows right on find closures is always a bit of trial and error.
crates/cli/src/config.rs
Outdated
| } | ||
|
|
||
| /// Converts some name or identity to an identity. If the input is None, None is returned. If an | ||
| /// identity is looked up and it doesn't exist, we panic. |
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.
Would be nice to add a bit to this comment about how map_name_to_identity is only called in contexts where the identity_or_name is known to exist (or be None), so the panic should be unreachable. Assuming that's the case.
crates/cli/src/config.rs
Outdated
|
|
||
| /// Converts some name or identity to an identity. If the input is None, None is returned. If an | ||
| /// identity is looked up and it doesn't exist, we panic. | ||
| pub fn map_name_to_identity(&self, identity_or_name: Option<&String>) -> Option<&String> { |
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.
Should probably take identity_or_name: Option<&str>.
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.
map_ function name makes me assume this is a higher-order function like Iterator::map. Perhaps resolve_name_to_identity is better?
| async fn exec_set_email(config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { | ||
| let email = args.get_one::<String>("email").unwrap().clone(); | ||
| let identity = args.get_one::<String>("identity").unwrap().clone(); | ||
| let identity = config.map_name_to_identity(args.get_one::<String>("identity")).unwrap(); |
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.
Should probably expect here to get a better error message.
| async fn exec_recover(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { | ||
| let email = args.get_one::<String>("email").unwrap(); | ||
| let identity = args.get_one::<String>("identity").unwrap().to_lowercase(); | ||
| let identity = config.map_name_to_identity(args.get_one::<String>("identity")).unwrap(); |
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.
Should probably also be an expect.
crates/cli/src/util.rs
Outdated
| Ok(identity_config.clone()) | ||
| if let Some(identity_or_name) = identity_or_name { | ||
| if is_hex_identity(identity_or_name) { | ||
| if let Some(identity_config) = config.get_identity_config_by_identity(identity_or_name) { |
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.
You should be able to write this conditional more succinctly as something like:
config.get_identity_config_by_identity(identity_or_name)
.map(Clone::clone)
.ok_or_else(|| anyhow::anyhow!("Missing identity credentials for identity: {}", identity_or_name))
Whether you think that's better is up to you.
crates/cli/src/util.rs
Outdated
| match config.map_name_to_identity(Some(&identity_or_name.to_string())) { | ||
| None => Err(anyhow::anyhow!("No such identity for name: {}", identity_or_name,)), | ||
| Some(_) => { | ||
| if let Some(identity_config) = config.get_identity_config_by_name(identity_or_name) { |
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.
Conditional can be rewritten as Option combinators, like above.
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.
Also, I believe this is the same conditional as above, so maybe it should be a named function.
crates/cli/src/config.rs
Outdated
| let configs = self.identity_configs_mut(); | ||
| for config in configs.iter_mut() { | ||
| if config.identity == identity { | ||
| config.nickname = Some(name); | ||
| return Ok(()); | ||
| } | ||
| } | ||
|
|
||
| Err(anyhow::anyhow!("Identity {} not found", identity)) |
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.
| let configs = self.identity_configs_mut(); | |
| for config in configs.iter_mut() { | |
| if config.identity == identity { | |
| config.nickname = Some(name); | |
| return Ok(()); | |
| } | |
| } | |
| Err(anyhow::anyhow!("Identity {} not found", identity)) | |
| self.get_identity_config_by_identity_mut(&identity) | |
| .ok_or_else(|| anyhow::anyhow!("Identity {} not found", identity)) | |
| .map(|c| c.nickname = Some(name)) |
crates/cli/src/config.rs
Outdated
| self.home.default_identity = Some(default_identity); | ||
| } | ||
|
|
||
| pub fn set_identity_nickname(&mut self, identity: String, name: String) -> Result<(), anyhow::Error> { |
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.
Let's add doc comments.
| async fn exec_token(config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { | ||
| let identity_or_name = config | ||
| .map_name_to_identity(args.get_one::<String>("identity")) | ||
| .unwrap() | ||
| .clone(); | ||
| let ic = config | ||
| .get_identity_config_by_identity(identity_or_name.as_str()) | ||
| .unwrap(); | ||
| println!("{}", ic.token); | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn exec_set_name(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { | ||
| let cloned_config = config.clone(); | ||
| let identity_or_name = cloned_config | ||
| .map_name_to_identity(args.get_one::<String>("identity")) | ||
| .unwrap(); | ||
| let new_name = args.get_one::<String>("name").unwrap(); | ||
| config.set_identity_nickname(identity_or_name.clone(), new_name.clone())?; | ||
| config.save(); | ||
| let ic = config | ||
| .get_identity_config_by_identity(identity_or_name.as_str()) | ||
| .unwrap(); | ||
| print_identity_config(ic); | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn exec_set_email(config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { |
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.
Doc comments
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com> Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com>
0bbb53d to
8cbe512
Compare
cloutiertyler
left a comment
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.
LGTM
* Working on improving commands that use identities * Fix lints * Reverted file that shouldn't have changed * Found and fixed all other todos * Addressed more CLI TODOs * Fixes for formatting issues * Set names of identities * Set name of identities + clippy * Small fix * Added the start of a doc comment, switching over to another PR * Fixed tests that needed to be updated * Addressed more feedback and fixed several clippy issues * Small fix * Apply suggestions from code review Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com> Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com> * Added more doc comments * Addressing more feedback * Fixed really old bug in SpacetimeDB * Tests to verify new functionality * Fix clippy lints * Email during identity creation is optional * Fix output so testsuite passes --------- Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com> Co-authored-by: Boppy <no-reply@boppygames.gg> Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
* Working on improving commands that use identities * Fix lints * Reverted file that shouldn't have changed * Found and fixed all other todos * Addressed more CLI TODOs * Fixes for formatting issues * Set names of identities * Set name of identities + clippy * Small fix * Added the start of a doc comment, switching over to another PR * Fixed tests that needed to be updated * Addressed more feedback and fixed several clippy issues * Small fix * Apply suggestions from code review Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com> Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com> * Added more doc comments * Addressing more feedback * Fixed really old bug in SpacetimeDB * Tests to verify new functionality * Fix clippy lints * Email during identity creation is optional * Fix output so testsuite passes --------- Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com> Co-authored-by: Boppy <no-reply@boppygames.gg> Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: NateTheDev1 <nthnlrichards@gmail.com>
* Circle splitting and recombining; Client re-coloring * Renamed Entity.id into Entity.entity_id * Client refactor; Polish; Bugfixes * Store username between game runs * Renamed EntityActor.OnUpdate to OnEntityUpdate * [WIP] C# server * [WIP] C# server * Changed `DateTimeOffset` to `long` in C# module * Parallax background * Animate entities when they get consumed * Fixed respawn button * Draft into Steve's branch (#12) * Small changes * Changes to align with the tutorial. * Fixed rebase issue * Merged ConnectionManager and EntityManager into GameManager for tutorial simplicity * Renaming Actor -> Controller for simplicity's sake, although Actor is a good name * actor -> entityController * Merged ArenaController into GameManager for simplicity and cleaned up a few things * Small cleanup to keep it in line with the tutorial * Small changes to how overlapping works * Rebrand to Blackholio * Rebrand to Blackholio (missed one) * Added a README.md * fixed readme --------- Co-authored-by: Steve Gibson <steve@clockwokrlabs.io> Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com> Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Fixes a margin for the figure that kinda breaks it on mobile
Co-authored-by: John <no-reply@boppygames.gg>
Co-authored-by: NateTheDev1 <nthnlrichards@gmail.com>
Co-authored-by: John <no-reply@boppygames.gg>
Description of Changes
New Features
You can now delete all identities by using
--allinspacetime identity remove:spacetime identity tokencan now be used to print out the token for an identity. Either the name of the identity or the identity itself can be passed in.You can also name or rename an identity using
spacetime identity set-name:Cards
This completes the following notion cards:
API
If the API is breaking, please state below what will break