From 78b5a6cd66f27095a782c39e11a4a333e21742d0 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 09:53:00 +0000 Subject: [PATCH] Initial upload: DotMigrate dotfiles migration tool with CI/CD --- src/cli/mod.rs | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/cli/mod.rs diff --git a/src/cli/mod.rs b/src/cli/mod.rs new file mode 100644 index 0000000..d936ed6 --- /dev/null +++ b/src/cli/mod.rs @@ -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, + + #[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, + + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + #[command(name = "init")] + Init { + #[arg(short, long)] + backend: Option, + }, + + #[command(name = "detect")] + Detect { + #[arg(short, long)] + output: Option, + + #[arg(short, long)] + include_system: bool, + }, + + #[command(name = "backup")] + Backup { + #[arg(short, long)] + output: Option, + + #[arg(short, long)] + backup_dir: Option, + }, + + #[command(name = "sync")] + Sync { + #[arg(short, long)] + remote: Option, + + #[arg(short, long)] + branch: Option, + + #[arg(short, long)] + strategy: Option, + }, + + #[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, + }, + + #[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), + } +}