Skip to main content

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