git_mover/
cli.rs

1//! Command line options for the git-mover tool
2use crate::{
3    config::GitMoverConfig, errors::GitMoverError, platform::PlatformType, utils::main_sync,
4};
5use clap::Parser;
6use serde::Deserialize;
7use std::path::PathBuf;
8
9/// git-mover - Move git repositories to a new location
10#[derive(Parser, Deserialize, Default, Clone, Debug)]
11pub struct GitMoverCli {
12    /// The source platform (github, gitlab, codeberg)
13    #[arg(long, visible_alias = "from")]
14    pub source: Option<PlatformType>,
15
16    /// The destination platform (github, gitlab, codeberg)
17    #[arg(long, visible_alias = "to")]
18    pub destination: Option<PlatformType>,
19
20    /// Don't sync forked repositories
21    #[arg(long = "no-forks")]
22    pub no_forks: bool,
23
24    /// Don't delete repositories
25    #[arg(long = "no-delete")]
26    pub no_delete: bool,
27
28    /// Resync all repositories
29    #[arg(long)]
30    pub resync: bool,
31
32    /// Custom configuration file path
33    #[arg(long)]
34    pub config: Option<PathBuf>,
35
36    /// Show the current config path and exit
37    #[arg(long)]
38    pub show_config_path: bool,
39
40    /// Sync manually
41    #[arg(long)]
42    pub manual: bool,
43
44    /// Verbose mode
45    #[arg(short, long, visible_short_alias = 'd', action = clap::ArgAction::Count)]
46    pub verbose: u8,
47}
48
49impl GitMoverCli {
50    /// Run the git-mover tool with the provided command line options
51    /// # Errors
52    /// Errors if something happens
53    pub async fn main(self) -> Result<(), GitMoverError> {
54        let config = GitMoverConfig::try_new(self)?;
55        if config.cli_args.show_config_path {
56            println!("{}", config.config_path.display());
57            return Ok(());
58        }
59        main_sync(config).await
60    }
61}
62
63/// Main git-mover cli
64/// # Errors
65/// Error if cli error
66pub async fn git_mover_main() -> Result<(), GitMoverError> {
67    let git_mover_inst = GitMoverCli::parse();
68    git_mover_inst.main().await
69}