use std::path::PathBuf;
use clap::Subcommand;
#[derive(Debug, Clone)]
pub enum GitSource {
Path(PathBuf),
Url(String),
}
impl GitSource {
pub fn parse(s: &str) -> Result<Self, String> {
if s.contains("://") || s.starts_with("git@") {
Ok(GitSource::Url(s.to_string()))
} else {
Ok(GitSource::Path(PathBuf::from(s)))
}
}
pub fn display(&self) -> String {
match self {
GitSource::Path(p) => p.display().to_string(),
GitSource::Url(u) => u.clone(),
}
}
}
pub(crate) fn parse_git_source(s: &str) -> Result<GitSource, String> {
GitSource::parse(s)
}
#[derive(Subcommand, Clone)]
pub enum ImportCommands {
Git {
#[arg(short, long, value_parser = parse_git_source)]
path: Option<GitSource>,
#[arg(long = "ref", value_name = "REF")]
refs: Vec<String>,
#[arg(long)]
lossy: bool,
},
}
#[derive(Subcommand, Clone)]
pub enum ExportCommands {
Git {
#[arg(short, long)]
destination: Option<std::path::PathBuf>,
},
}
#[derive(Subcommand, Clone, Debug)]
pub enum SyncCommands {
Git {
#[arg(short, long, value_parser = parse_git_source)]
path: Option<GitSource>,
},
}