Skip to content

Commit

Permalink
feat: .info role/.exit role works for session role
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Oct 29, 2024
1 parent 740f406 commit 856eb9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,15 @@ impl Config {
} else {
flags |= StateFlags::SESSION;
}
if session.role_name().is_some() {
flags |= StateFlags::ROLE;
}
} else if self.role.is_some() {
flags |= StateFlags::ROLE;
}
if self.agent.is_some() {
flags |= StateFlags::AGENT;
}
if self.role.is_some() {
flags |= StateFlags::ROLE;
}
if self.rag.is_some() {
flags |= StateFlags::RAG;
}
Expand Down Expand Up @@ -843,22 +845,24 @@ impl Config {
}

pub fn role_info(&self) -> Result<String> {
if let Some(role) = &self.role {
return Ok(role.export());
} else if let Some(session) = &self.session {
let role = session.to_role();
if !role.name().is_empty() {
return Ok(role.export());
if let Some(session) = &self.session {
if session.role_name().is_some() {
let role = session.to_role();
Ok(role.export())
} else {
bail!("No session role")
}
} else if let Some(role) = &self.role {
Ok(role.export())
} else {
bail!("No role")
}
bail!("No role");
}

pub fn exit_role(&mut self) -> Result<()> {
if self.role.is_some() {
if let Some(session) = self.session.as_mut() {
session.clear_role();
}
if let Some(session) = self.session.as_mut() {
session.clear_role();
} else if self.role.is_some() {
self.role = None;
}
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions src/config/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ impl Session {
&self.name
}

pub fn role_name(&self) -> Option<&str> {
self.role_name.as_deref()
}

pub fn dirty(&self) -> bool {
self.dirty
}
Expand Down

0 comments on commit 856eb9b

Please sign in to comment.