mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-09-20 08:05:04 +02:00
feat(user): list user orgs
This commit is contained in:
parent
ed4bed4ca7
commit
2aa4b152ff
1 changed files with 53 additions and 0 deletions
53
src/user.rs
53
src/user.rs
|
@ -56,6 +56,10 @@ pub enum UserSubcommand {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
sort: Option<RepoSortOrder>,
|
sort: Option<RepoSortOrder>,
|
||||||
},
|
},
|
||||||
|
Orgs {
|
||||||
|
/// The name of the user to view org membership of
|
||||||
|
user: Option<String>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserCommand {
|
impl UserCommand {
|
||||||
|
@ -78,6 +82,7 @@ impl UserCommand {
|
||||||
starred,
|
starred,
|
||||||
sort,
|
sort,
|
||||||
} => list_repos(&api, user.as_deref(), starred, sort).await?,
|
} => list_repos(&api, user.as_deref(), starred, sort).await?,
|
||||||
|
UserSubcommand::Orgs { user } => list_orgs(&api, user.as_deref()).await?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -370,3 +375,51 @@ async fn list_repos(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn list_orgs(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
|
||||||
|
let mut orgs = match user {
|
||||||
|
Some(user) => {
|
||||||
|
let query = forgejo_api::structs::OrgListUserOrgsQuery {
|
||||||
|
limit: Some(u32::MAX),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
api.org_list_user_orgs(user, query).await?
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let query = forgejo_api::structs::OrgListCurrentUserOrgsQuery {
|
||||||
|
limit: Some(u32::MAX),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
api.org_list_current_user_orgs(query).await?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if orgs.is_empty() {
|
||||||
|
match user {
|
||||||
|
Some(user) => println!("{user} is not a member of any organizations"),
|
||||||
|
None => println!("You are not a member of any organizations"),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
orgs.sort_unstable_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
|
||||||
|
let SpecialRender { bullet, dash, .. } = *crate::special_render();
|
||||||
|
for org in &orgs {
|
||||||
|
let name = org.name.as_deref().ok_or_eyre("org does not have name")?;
|
||||||
|
let full_name = org
|
||||||
|
.full_name
|
||||||
|
.as_deref()
|
||||||
|
.ok_or_eyre("org does not have name")?;
|
||||||
|
if !full_name.is_empty() {
|
||||||
|
println!("{bullet} {name} {dash} \"{full_name}\"");
|
||||||
|
} else {
|
||||||
|
println!("{bullet} {name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if orgs.len() == 1 {
|
||||||
|
println!("1 organization");
|
||||||
|
} else {
|
||||||
|
println!("{} organizations", orgs.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue