Initial upload: DotMigrate dotfiles migration tool with CI/CD
This commit is contained in:
143
src/cli/mod.rs
Normal file
143
src/cli/mod.rs
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
pub mod commands;
|
||||||
|
pub use commands::{init, detect, backup, sync, merge, status, diff, completions};
|
||||||
|
|
||||||
|
use clap::{Parser, Subcommand, ValueEnum};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, ValueEnum)]
|
||||||
|
pub enum SyncBackend {
|
||||||
|
Git,
|
||||||
|
S3,
|
||||||
|
Direct,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, ValueEnum)]
|
||||||
|
pub enum Platform {
|
||||||
|
Linux,
|
||||||
|
Macos,
|
||||||
|
Wsl,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, ValueEnum)]
|
||||||
|
pub enum MergeStrategy {
|
||||||
|
Diff3,
|
||||||
|
Ours,
|
||||||
|
Theirs,
|
||||||
|
Ask,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(name = "dotmigrate")]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
pub struct Args {
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
pub config: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
pub dry_run: bool,
|
||||||
|
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
pub verbose: bool,
|
||||||
|
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
pub backend: Option<SyncBackend>,
|
||||||
|
|
||||||
|
#[command(subcommand)]
|
||||||
|
pub command: Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
pub enum Commands {
|
||||||
|
#[command(name = "init")]
|
||||||
|
Init {
|
||||||
|
#[arg(short, long)]
|
||||||
|
backend: Option<SyncBackend>,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "detect")]
|
||||||
|
Detect {
|
||||||
|
#[arg(short, long)]
|
||||||
|
output: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
include_system: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "backup")]
|
||||||
|
Backup {
|
||||||
|
#[arg(short, long)]
|
||||||
|
output: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
backup_dir: Option<PathBuf>,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "sync")]
|
||||||
|
Sync {
|
||||||
|
#[arg(short, long)]
|
||||||
|
remote: Option<String>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
branch: Option<String>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
strategy: Option<MergeStrategy>,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "merge")]
|
||||||
|
Merge {
|
||||||
|
#[arg(short, long)]
|
||||||
|
base: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
local: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
remote: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
output: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
strategy: Option<MergeStrategy>,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "status")]
|
||||||
|
Status {
|
||||||
|
#[arg(short, long)]
|
||||||
|
detailed: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "diff")]
|
||||||
|
Diff {
|
||||||
|
#[arg(short, long)]
|
||||||
|
local: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
remote: PathBuf,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(name = "completions")]
|
||||||
|
Completions {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
shell: clap_complete::Shell,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute(args: Args) -> anyhow::Result<()> {
|
||||||
|
if args.verbose {
|
||||||
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug"))
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
match &args.command {
|
||||||
|
Commands::Init { backend } => init(args.clone(), *backend),
|
||||||
|
Commands::Detect { output, include_system } => detect(args.clone(), output.clone(), *include_system),
|
||||||
|
Commands::Backup { output, backup_dir } => backup(args.clone(), output.clone(), backup_dir.clone()),
|
||||||
|
Commands::Sync { remote, branch, strategy } => sync(args.clone(), remote.clone(), branch.clone(), strategy.clone()),
|
||||||
|
Commands::Merge { base, local, remote, output, strategy } => merge(args.clone(), base.clone(), local.clone(), remote.clone(), output.clone(), strategy.clone()),
|
||||||
|
Commands::Status { detailed } => status(args.clone(), *detailed),
|
||||||
|
Commands::Diff { local, remote } => diff(args.clone(), local.clone(), remote.clone()),
|
||||||
|
Commands::Completions { shell } => completions(*shell),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user