Skip to content

Commit 60d0a8e

Browse files
authored
enforece login (#3339)
1 parent 79264d5 commit 60d0a8e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

crates/chat-cli/src/cli/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,23 @@ impl RootSubcommand {
133133
matches!(self, Self::Chat(_) | Self::Login(_) | Self::Profile | Self::Issue(_))
134134
}
135135

136-
pub fn requires_auth(&self) -> bool {
137-
matches!(self, Self::Chat(_) | Self::Profile)
138-
}
139-
140136
pub async fn execute(self, os: &mut Os) -> Result<ExitCode> {
141137
// Check for auth on subcommands that require it.
142-
if self.requires_auth() && !is_logged_in(&mut os.database).await {
143-
bail!(
144-
"You are not logged in, please log in with {}",
145-
StyledText::command(&format!("{CLI_BINARY_NAME} login"))
146-
);
138+
if !is_logged_in(&mut os.database).await {
139+
if matches!(self, Self::Chat(_)) {
140+
let options = ["Yes", "No"];
141+
match crate::util::choose(" You are not logged in. Login now?", &options)? {
142+
Some(0) => {},
143+
_ => bail!("Login is required to use chat"),
144+
}
145+
146+
LoginArgs::default().execute(os).await?;
147+
} else if matches!(self, Self::Profile) {
148+
bail!(
149+
"You are not logged in, please log in with {}",
150+
StyledText::command(&format!("{CLI_BINARY_NAME} login"))
151+
);
152+
}
147153
}
148154

149155
// Daily heartbeat check

0 commit comments

Comments
 (0)