Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use crate::csmrc::Config;
use clap::{CommandFactory, Parser, Subcommand};
use log::{LevelFilter, debug, error, info, warn};
use std::fmt;
use std::fs::File;
use std::io::Write;
use std::io::{self, Write};

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `self`

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `self`

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `self`

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `self`

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `self`

Check warning on line 13 in src/main.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `self`
use std::path::Path;
use std::process::ExitCode;

Expand Down Expand Up @@ -48,6 +49,28 @@
},
}

trait CSMResult {
fn finish(&self) -> ExitCode;
}

impl CSMResult for ExitCode {
fn finish(&self) -> Self {
*self
}
}

impl<T, E: fmt::Display> CSMResult for Result<T, E> {
fn finish(&self) -> ExitCode {
match self {
Ok(_) => ExitCode::SUCCESS,
Err(e) => {
error!("{}", e);
ExitCode::FAILURE
}
}
}
}

fn main() -> ExitCode {
let cli = Cli::parse();

Expand Down Expand Up @@ -95,11 +118,11 @@
}

match cli.command {
Command::Env(sub) => env::run(config, sub),
Command::Robot(sub) => robot::run(config, sub),
Command::Env(sub) => env::run(config, sub).finish(),
Command::Robot(sub) => robot::run(config, sub).finish(),
Command::Init { shell, code } => {
let mut cmd = Cli::command();
init::run(config, shell, code, &mut cmd)
init::run(config, shell, code, &mut cmd).finish()
}
}
}
Expand Down
Loading