memstead_cli/commands/
logout.rs1use clap::Parser;
5use serde_json::json;
6
7use crate::auth::credentials;
8use crate::output::{print_json, print_markdown};
9use crate::registry;
10use crate::setup::CliContext;
11
12#[derive(Parser, Debug)]
13pub struct Args {
14 #[arg(long, value_name = "URL")]
16 pub registry: Option<String>,
17}
18
19pub fn run(ctx: &CliContext, args: Args) -> anyhow::Result<()> {
20 let base = registry::registry_base(args.registry.as_deref());
21 let host = registry::registry_host(&base);
22
23 let removed = credentials::remove_for(&host)?;
24
25 if ctx.json {
26 print_json(&json!({ "ok": true, "registry": host, "removed": removed }))?;
27 } else if removed {
28 print_markdown(&format!("# Logged out from {host}"));
29 } else {
30 print_markdown(&format!("# Not logged in to {host} (nothing to remove)"));
31 }
32 Ok(())
33}