mod cleanup;
mod init;
mod ls;
mod run;
mod stop;
mod terminal;
use std::{path::PathBuf, time::Duration};
use clap::{Parser, Subcommand};
use color_eyre::Section;
use crate::{crate_info, error::UserError, scell::types::name::TargetName};
const MIN_FPS: Duration = Duration::from_millis(1000 / 60);
#[derive(Parser)]
#[clap(version = crate_info::version())]
#[clap(about = crate_info::description())]
pub struct Cli {
#[clap(value_name = "FILE", default_value = ".")]
scell_path: PathBuf,
#[clap(short, long)]
target: Option<TargetName>,
#[clap(short, long)]
detach: bool,
#[clap(short, long)]
quiet: bool,
#[clap(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
Init {
#[clap(value_name = "PATH", default_value = ".")]
path: PathBuf,
},
Ls,
Stop,
Cleanup {
#[clap(long)]
all: bool,
},
}
impl Cli {
pub async fn exec(self) -> color_eyre::Result<()> {
const SUGGESTION: &str = "If you've got a second, please toss a full backtrace into your ticket—it helps us squash the bug way faster! You can grab it by running the app with `RUST_BACKTRACE=1`.";
self.exec_inner().await.map_err(|e| {
if e.is::<UserError>() {
e
} else {
e.note(format!(
"Internal bug, please report it `{}/issues/new`",
crate_info::repository()
))
.suggestion(SUGGESTION)
}
})?;
Ok(())
}
pub async fn exec_inner(self) -> color_eyre::Result<()> {
match self.command {
None => run::run(self.scell_path, self.target, self.detach, self.quiet).await?,
Some(Commands::Init { path }) => init::init(path)?,
Some(Commands::Ls) => ls::ls().await?,
Some(Commands::Stop) => stop::stop().await?,
Some(Commands::Cleanup { all }) => cleanup::cleanup(all).await?,
}
Ok(())
}
}