1pub mod agent;
2pub mod cli;
3
4use agent::{
5 running_agents::{
6 check_agents, get_current_agents, purge_empty_agents, resolve_agent_pids,
7 RunningAgentCheckStatus,
8 },
9 Agent,
10};
11use inquire::{Confirm, Select};
12use std::io;
13
14pub fn basic_operation() -> io::Result<()> {
15 let agents: Vec<Agent> = get_current_agents()?;
16 let agents = resolve_agent_pids(&agents);
17 let agents = {
18 if agents.len() > 1 {
19 let message =
20 "Found multiple running agents, would you like to terminate all but 1 without identities?";
21 let response = Confirm::new(message)
22 .with_default(true)
23 .with_help_message("Terminates all but 1 empty agents by default")
24 .prompt();
25
26 match response {
27 Ok(true) => purge_empty_agents(agents),
28 Ok(false) => agents,
29 Err(e) => {
30 println!(
31 "Something went wrong with the prompt; continuing without terminating"
32 );
33 eprintln!("Error: {}", e);
34 agents
35 }
36 }
37 } else {
38 agents
39 }
40 };
41
42 match check_agents(&agents) {
43 RunningAgentCheckStatus::SingleAgent(agent) => {
44 agent.print_env_commands();
48 }
49 RunningAgentCheckStatus::MultipleAgents => {
50 let resp = Select::new("Multiple agents are running; you can pick an agent to print environment variables for", agents)
51 .prompt();
52 match resp {
53 Ok(choice) => {
54 choice.print_env_commands();
55 }
56 Err(e) => {
57 eprintln!("Failed to select agent: {}", e);
58 }
59 }
60 }
61 RunningAgentCheckStatus::NoAgents => {
62 println!(r#"No running agents; start your own with `eval $(ssh-agent -s)`"#);
63 }
64 }
65
66 Ok(())
67}