codeberg_cli/actions/repo/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pub mod assignees;
pub mod clone;
pub mod create;
pub mod delete;
pub mod fork;
pub mod info;

use clap::Subcommand;

use super::GeneralArgs;

/// Repository subcommands
#[derive(Subcommand, Debug)]
pub enum RepoArgs {
    Create(create::RepoCreateArgs),
    Clone(clone::RepoCloneArgs),
    Delete(delete::RepoDeleteArgs),
    Fork(fork::RepoForkArgs),
    Info(info::RepoInfoArgs),
    Assignees(assignees::RepoAssigneesArgs),
}

impl RepoArgs {
    pub async fn run(self, general_args: GeneralArgs) -> anyhow::Result<()> {
        match self {
            RepoArgs::Create(args) => args.run(general_args).await,
            RepoArgs::Clone(args) => args.run(general_args).await,
            RepoArgs::Delete(args) => args.run(general_args).await,
            RepoArgs::Fork(args) => args.run(general_args).await,
            RepoArgs::Info(args) => args.run(general_args).await,
            RepoArgs::Assignees(args) => args.run(general_args).await,
        }
    }
}

/// parses a string of format OWNER/REPO
fn parse_owner_and_repo(owner_and_repo: &str) -> anyhow::Result<(String, String)> {
    owner_and_repo
        .split_once('/')
        .map(|(owner, repo)| (owner.to_owned(), repo.to_owned()))
        .ok_or_else(|| {
            anyhow::anyhow!(
                "Please provide the repository you want to clone in the format OWNER/REPO."
            )
        })
}