use anyhow::Result;
use crate::commands::{profiles, skills};
use crate::config::list_profile_names;
const DEFAULT_PROFILE_NAME: &str = "default";
pub struct InitArgs {
pub url: Option<String>,
pub region: Option<String>,
pub api_key: Option<String>,
pub oauth: bool,
pub install_skills: bool,
pub agents: Vec<String>,
pub scope: Option<skills::SkillsScope>,
}
pub async fn run_init(args: InitArgs) -> Result<()> {
let InitArgs {
url,
region,
api_key,
oauth,
install_skills,
agents,
scope,
} = args;
if list_profile_names()?.is_empty() {
let oauth = oauth || api_key.is_none();
println!("Setting up your Coralogix profile...\n");
profiles::run_add(profiles::AddArgs {
name: Some(DEFAULT_PROFILE_NAME.to_string()),
url,
region,
api_key,
oauth,
force: false,
set_default: false,
quick: true,
})
.await?;
} else {
println!("A Coralogix profile is already configured - skipping profile setup.");
}
if install_skills {
println!("\nInstalling the cx agent skills for coding agents...");
match skills::run_install(skills::InstallOptions {
scope,
agents,
skip_if_installed: true,
}) {
Ok(skills::InstallOutcome::Installed) => {}
Ok(skills::InstallOutcome::AlreadyInstalled) => {
println!(
"cx agent skills are already installed - skipping.\n\
Update them anytime with `cx skills install`."
);
}
Err(error) => eprintln!("warning: skipped the agent-skills install: {error:#}"),
}
}
print_success();
Ok(())
}
fn print_success() {
println!("\ncx is ready to go.");
println!("Try it out:");
println!(" cx logs 'source logs | limit 10'");
println!(" cx schema # discover every command as JSON");
}