-
Notifications
You must be signed in to change notification settings - Fork 17
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
chore(iota)!: Set active env when adding new env if empty #5330
base: develop
Are you sure you want to change the base?
Changes from 2 commits
874f89b
90167d3
135d703
201921a
95c6bf5
978e3bb
f9a099d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,17 +79,18 @@ impl IotaClientConfig { | |
} | ||
|
||
/// Get the first [`IotaEnv`] or one by its alias. | ||
pub fn get_env(&self, alias: &Option<String>) -> Option<&IotaEnv> { | ||
if let Some(alias) = alias { | ||
self.envs.iter().find(|env| &env.alias == alias) | ||
} else { | ||
self.envs.first() | ||
} | ||
pub fn get_env(&self, alias: &str) -> Option<&IotaEnv> { | ||
self.envs.iter().find(|env| &env.alias == alias) | ||
DaughterOfMars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Get the active [`IotaEnv`]. | ||
pub fn get_active_env(&self) -> Result<&IotaEnv, anyhow::Error> { | ||
self.get_env(&self.active_env).ok_or_else(|| { | ||
if let Some(active_env) = &self.active_env { | ||
self.get_env(active_env) | ||
} else { | ||
self.envs.first() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a mutable fn and I don't think it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but the API is kind of lying to the user, because the object's internal state doesn't reflect what the method returns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's true. If there's no env the default is the first, which is represented in the state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently |
||
.ok_or_else(|| { | ||
anyhow!( | ||
"Environment configuration not found for env [{}]", | ||
self.active_env.as_deref().unwrap_or("None") | ||
|
@@ -99,12 +100,11 @@ impl IotaClientConfig { | |
|
||
/// Add an [`IotaEnv`]. | ||
pub fn add_env(&mut self, env: IotaEnv) { | ||
if !self | ||
.envs | ||
.iter() | ||
.any(|other_env| other_env.alias == env.alias) | ||
{ | ||
self.envs.push(env) | ||
if self.get_env(&env.alias).is_none() { | ||
if self.active_env.is_none() { | ||
self.set_active_env(env.alias.clone()); | ||
} | ||
self.envs.push(env); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the environment should also be set to active in case the user tried to add the same environment again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand. You mean if the env exists and they try to add it again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay then ... I would still update the docs for this method to mention that it also sets the new env as active (but only if it was unknown before) |
||
} | ||
} | ||
} | ||
|
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 don't really know how to feel about this change tbh
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.
How so?