aimo 0.1.12

just another [ai] model orchestrator
Documentation
use minimo::*;
use std::env;

const BANNER: &str = r#"
                    /██                        
                   |__/                        
           /██████  /██ /██████/████   /██████ 
          |____  ██| ██| ██_  ██_  ██ /██__  ██
           /███████| ██| ██ \ ██ \ ██| ██  \ ██
          /██__  ██| ██| ██ | ██ | ██| ██  | ██
         |  ███████| ██| ██ | ██ | ██|  ██████/
          \_______/|__/|__/ |__/ |__/ \______/ 
                                               
"#;

const DESCRIPTION: &str = r#"all rights to the code and any associated intellectual property are reserved (hopefully) by the developer of this software [incredimo]. by using this software, you are agreeing that the developer will not  be held responsible to any damages,losses,lawsuits, or divorces that may be caused directly or indirectly by the use of this software. If it summons a horde of tap-dancing llamas or accidentally opens a  portal to another dimension, you're on your own. you agree that the  developer is not liable for supernatural possessions, spontaneous  time travel or sudden urges to breakdance in public. if you expirence any sudden shifts in reality or feel like you are being watched by aliens, it is recommended that you take a break and go outside. remember, normal is just a setting on your washing machine.
"#;

pub fn display_banner() {
    BANNER.print(in_white);
    divider_vibrant();
    let version = env!("CARGO_PKG_VERSION");
    showln!(
        white_bold, "AI MODEL ORCHESTRATOR", gray_dim, " | ", orange_bold, version, gray_dim, " | ",
        yellow_bold, "github.com/incredimo"
    );
    divider_vibrant();
    showln!(
        gray_dim,
        "use ", yellow_bold, "--help", gray_dim, " and ", yellow_bold, "--info", gray_dim,
        " when you need help or information."
    );
    showln!(
        gray_dim,
        "you can pick the model (", yellow_bold, "--model", gray_dim, "), role (", yellow_bold,
        "--role", gray_dim, "), and\nsession (", yellow_bold, "--session", gray_dim,
        ") or aimo will pick one for you."
    );
    showln!(
        gray_dim,
        "to list all available models, roles, or sessions, use \n", yellow_bold, "--list-models",
        gray_dim, ", ", yellow_bold, "--list-roles", gray_dim, ", or ", yellow_bold,
        "--list-sessions", gray_dim, "."
    );
    showln!(
        gray_dim,
        "you can also use the ", yellow_bold, "--serve", gray_dim, " to start a web server."
    );
    showln!(
        gray_dim,
        "to execute commands in natural language, use ", yellow_bold, "--execute", gray_dim, "."
    );
    showln!(
        gray_dim,
        "to include files with the message, use ", yellow_bold, "--file", gray_dim,
        "followed \nby the file name.", gray_dim, "press ", yellow_bold, "ctrl+d", gray_dim,
        " to exit the program."
    );
    divider();
}

pub struct Cli {
    pub model: Option<String>,
    pub prompt: Option<String>,
    pub role: Option<String>,
    pub session: Option<Option<String>>,
    pub save_session: bool,
    pub serve: Option<Option<String>>,
    pub execute: bool,
    pub code: bool,
    pub file: Vec<String>,
    pub no_highlight: bool,
    pub no_stream: bool,
    pub wrap: Option<String>,
    pub light_theme: bool,
    pub dry_run: bool,
    pub info: bool,
    pub list_models: bool,
    pub list_roles: bool,
    pub list_sessions: bool,
    pub text: Vec<String>,
}

impl Cli {
    pub fn parse() -> Cli {
        let mut args = env::args().skip(1);
        let mut model = None;
        let mut prompt = None;
        let mut role = None;
        let mut session = None;
        let mut save_session = false;
        let mut serve = None;
        let mut execute = false;
        let mut code = false;
        let mut file = Vec::new();
        let mut no_highlight = false;
        let mut no_stream = false;
        let mut wrap = None;
        let mut light_theme = false;
        let mut dry_run = false;
        let mut info = false;
        let mut list_models = false;
        let mut list_roles = false;
        let mut list_sessions = false;
        let mut text = Vec::new();

        while let Some(arg) = args.next() {
            match arg.as_str() {
                "--model" => {
                    if let Some(value) = args.next() {
                        model = Some(value);
                    }
                }
                "--prompt" => {
                    if let Some(value) = args.next() {
                        prompt = Some(value);
                    }
                }
                "--role" => {
                    if let Some(value) = args.next() {
                        role = Some(value);
                    }
                }
                "--session" => {
                    if let Some(value) = args.next() {
                        session = Some(Some(value));
                    } else {
                        session = Some(None);
                    }
                }
                "--save-session" => save_session = true,
                "--serve" => {
                    if let Some(value) = args.next() {
                        serve = Some(Some(value));
                    } else {
                        serve = Some(None);
                    }
                }
                "--execute" => execute = true,
                "--code" => code = true,
                "--file" => {
                    if let Some(value) = args.next() {
                        file.push(value);
                    }
                }
                "--no-highlight" => no_highlight = true,
                "--no-stream" => no_stream = true,
                "--wrap" => {
                    if let Some(value) = args.next() {
                        wrap = Some(value);
                    }
                }
                "--light-theme" => light_theme = true,
                "--dry-run" => dry_run = true,
                "--info" => info = true,
                "--list-models" => list_models = true,
                "--list-roles" => list_roles = true,
                "--list-sessions" => list_sessions = true,
                _ => text.push(arg),
            }
        }

        Cli {
            model,
            prompt,
            role,
            session,
            save_session,
            serve,
            execute,
            code,
            file,
            no_highlight,
            no_stream,
            wrap,
            light_theme,
            dry_run,
            info,
            list_models,
            list_roles,
            list_sessions,
            text,
        }
    }

    pub fn text(&self) -> Option<String> {
        let text = self
            .text
            .iter()
            .map(|x| x.trim().to_string())
            .collect::<Vec<String>>()
            .join(" ");
        if text.is_empty() {
            None
        } else {
            Some(text)
        }
    }
}