microci 0.1.2

Porting of MicroCI tool - Minimalist Continuous Integration Tool
use clap::Parser;

pub fn main() {
    let args = Args::parse();

    if args.update {
        return update();
    }

    if args.update_dev {
        return update_dev();
    }

    if args.uninstall {
        return uninstall();
    }

    // ../../microci-ref/src/main.cpp

    help();
}

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// Update microCI to stable stream
    #[arg(short, long, default_value_t = false)]
    update: bool,

    /// Update microCI to development stream
    #[arg(short = 'D', long, default_value_t = false)]
    update_dev: bool,

    /// Uninstall
    #[arg(short = 'x', long, default_value_t = false)]
    uninstall: bool,

    /// Load pipeline steps from file
    #[arg(short, long, default_value_t = String::from(".microCI.yml"))]
    input: String,
}

// Name of the person to greet
// #[arg(short, long)]
// name: String,

// Number of times to greet
// #[arg(short, long, default_value_t = 1)]
// count: u8,

pub fn update() {
    let cmds = r#"
echo "🚀 Updating to the latest stable release..."
sudo curl -fsSL \
  github.com/geraldolsribeiro/microci/releases/latest/download/microCI \
  -o /usr/bin/microCI
sudo chmod 755 /usr/bin/microCI
microCI --version
"#;
    println!("{}", cmds)
}

pub fn update_dev() {
    let cmds = r#"
echo "🚧 Updating to the development stream..."
sudo curl -fsSL \
  github.com/geraldolsribeiro/microci/releases/download/latest/microCI \
  -o /usr/bin/microCI
sudo chmod 755 /usr/bin/microCI
microCI --version
"#;
    println!("{}", cmds)
}

pub fn uninstall() {
    let cmds = r#"
echo "🔥 Removing microCI..."
sudo rm -f /usr/bin/microCI
"#;
    println!("{}", cmds)
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
fn help() {
    println!(
        "Options:
  -h,--help                Print this help
  -V,--version             Print the microCI version
  -T,--test-config         Configuration test
  -A,--activity-diagram    Generate activity diagram
  -a,--append-log          Append log
  -O,--only name           Execute only a single step
  -l,--list                List steps
  -N,--number N            Execute the Nth step
  -x,--hash hh             Execute the hh step
  -U,--update-db           Update observability database
  -u,--update              Update microCI to stable stream
  -D,--update-dev          Update microCI to development stream
  -x,--uninstall           Uninstall
  -i,--input file.yml      Load the configuration from file.yml
  -H,--home alt_home_dir   Alternative home directory
  -n,--config gitlab_ci    Create a .gitlab-ci.yml example config
  -n,--new skip            Create a placeholder step
  -n,--new bash            Create a command line step
  -n,--new docmd           Create a documentation step
  -n,--new mkdocs_material Create a documentation step
  -n,--new doxygen         Create a documentation step
  -n,--new pandoc          Create a document conversion step
  -n,--new git_publish     Create a publish step
  -n,--new git_deploy      Create a production deploy step
  -n,--new plantuml        Create a diagram generation step
  -n,--new pikchr          Create a diagram generation step
  -n,--new clang-format    Create a code format step
  -n,--new vhdl-format     Create a code format step
  -n,--new beamer          Create a PDF presentation step
  -n,--new fetch           Create a download external artfact step
  -n,--new minio           Create a upload/download internal artifact step
  -n,--new cppcheck        Create a C++ SAST step
  -n,--new clang-tidy      Create a C++ SAST step
  -n,--new flawfinder      Create a C++ SAST step
  -n,--new docker_build    Create a local docker build step
  -n,--new template        Create a template step
"
    )
}

pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}