Skip to content

Commit 46348df

Browse files
authored
refactor: allow .edit role in empty session with role (#1031)
1 parent 6b6413b commit 46348df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/config/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,17 @@ impl Config {
915915
}
916916

917917
pub fn edit_role(&mut self) -> Result<()> {
918-
if let Some(name) = self.role.as_ref().map(|v| v.name().to_string()) {
918+
if let Some(session) = self.session.as_ref() {
919+
if let Some(name) = session.role_name().map(|v| v.to_string()) {
920+
if session.is_empty() {
921+
self.upsert_role(&name)
922+
} else {
923+
bail!("Cannot perform this operation because you are in a non-empty session")
924+
}
925+
} else {
926+
bail!("No role")
927+
}
928+
} else if let Some(name) = self.role.as_ref().map(|v| v.name().to_string()) {
919929
self.upsert_role(&name)
920930
} else {
921931
bail!("No role")

src/repl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ lazy_static::lazy_static! {
5353
ReplCommand::new(
5454
".edit role",
5555
"Edit the current role",
56-
AssertState::TrueFalse(StateFlags::ROLE, StateFlags::SESSION_EMPTY | StateFlags::SESSION),
56+
AssertState::TrueFalse(StateFlags::ROLE, StateFlags::SESSION),
5757
),
5858
ReplCommand::new(
5959
".save role",

0 commit comments

Comments
 (0)