semora-cli 0.4.0

Semora CLI: publish Markdown and HTML, and hear back from the page
Documentation
//! `semora skill`: the agent guide (same text as the server's `/docs.md`).

use crate::config::origin;
use crate::{Ctx, exit};

pub const TEXT: &str = semora_proto::GUIDE;

/// The guide with the configured server in place of the example host.
pub fn text(ctx: &Ctx) -> String {
    match &ctx.settings.server {
        Some(server) => {
            let base = origin(server);
            let ws = match base.strip_prefix("https://") {
                Some(rest) => format!("wss://{rest}"),
                None => base.replacen("http://", "ws://", 1),
            };
            TEXT.replace("wss://semora.example.com", &ws)
                .replace("https://semora.example.com", &base)
        }
        None => TEXT.to_string(),
    }
}

pub fn run(ctx: &Ctx) -> anyhow::Result<i32> {
    print!("{}", text(ctx));
    Ok(exit::OK)
}