cargo_tangle/create/
source.rs

1use clap::Args;
2use std::path::PathBuf;
3
4#[derive(Args, Debug, Clone, Default)]
5#[group(id = "source", required = false, multiple = false)]
6pub struct Source {
7    #[command(flatten)]
8    repo: Option<RepoArgs>,
9
10    #[arg(short, long, group = "source")]
11    path: Option<PathBuf>,
12}
13
14#[derive(Args, Debug, Clone)]
15#[group(requires = "repo")]
16pub struct RepoArgs {
17    #[arg(short, long, env, required = false, group = "source")]
18    repo: String,
19    #[arg(short, long, env)]
20    branch: Option<String>,
21    #[arg(short, long, env, conflicts_with = "branch")]
22    tag: Option<String>,
23}
24
25impl From<Source> for Option<cargo_generate::TemplatePath> {
26    fn from(value: Source) -> Self {
27        let mut template_path = cargo_generate::TemplatePath::default();
28
29        match value {
30            Source {
31                repo: Some(repo_args),
32                ..
33            } => {
34                template_path.git = Some(repo_args.repo);
35                template_path.branch = repo_args.branch;
36                template_path.tag = repo_args.tag;
37                Some(template_path)
38            }
39            Source {
40                path: Some(path), ..
41            } => {
42                template_path.path = Some(path.to_string_lossy().into());
43                Some(template_path)
44            }
45            Source {
46                repo: None,
47                path: None,
48            } => None,
49        }
50    }
51}