mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2025-02-17 09:28:39 +01:00
feat: wiki contents
This commit is contained in:
parent
eadadf8dd8
commit
296ac0c853
1 changed files with 36 additions and 5 deletions
41
src/wiki.rs
41
src/wiki.rs
|
@ -1,6 +1,11 @@
|
|||
use clap::{Args, Subcommand};
|
||||
use eyre::OptionExt;
|
||||
use forgejo_api::Forgejo;
|
||||
|
||||
use crate::repo::{RepoArg, RepoInfo};
|
||||
use crate::{
|
||||
repo::{RepoArg, RepoInfo, RepoName},
|
||||
SpecialRender,
|
||||
};
|
||||
|
||||
#[derive(Args, Clone, Debug)]
|
||||
pub struct WikiCommand {
|
||||
|
@ -12,7 +17,9 @@ pub struct WikiCommand {
|
|||
}
|
||||
|
||||
#[derive(Subcommand, Clone, Debug)]
|
||||
pub enum WikiSubcommand {}
|
||||
pub enum WikiSubcommand {
|
||||
Contents { repo: Option<RepoArg> },
|
||||
}
|
||||
|
||||
impl WikiCommand {
|
||||
pub async fn run(self, keys: &mut crate::KeyInfo, host_name: Option<&str>) -> eyre::Result<()> {
|
||||
|
@ -22,20 +29,44 @@ impl WikiCommand {
|
|||
let api = keys.get_api(repo.host_url()).await?;
|
||||
let repo = repo.name().ok_or_else(|| self.no_repo_error())?;
|
||||
|
||||
match self.command {}
|
||||
match self.command {
|
||||
Contents { repo: _ } => wiki_contents(&repo, &api).await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn repo(&self) -> Option<&RepoArg> {
|
||||
use WikiSubcommand::*;
|
||||
match &self.command {
|
||||
_ => todo!(),
|
||||
Contents { repo } => repo.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
fn no_repo_error(&self) -> eyre::Error {
|
||||
use WikiSubcommand::*;
|
||||
match &self.command {
|
||||
_ => todo!(),
|
||||
Contents { repo: _ } => eyre::eyre!("couldn't guess repo"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn wiki_contents(repo: &RepoName, api: &Forgejo) -> eyre::Result<()> {
|
||||
let SpecialRender { bullet, .. } = *crate::special_render();
|
||||
|
||||
let query = forgejo_api::structs::RepoGetWikiPagesQuery {
|
||||
page: None,
|
||||
limit: None,
|
||||
};
|
||||
let pages = api
|
||||
.repo_get_wiki_pages(repo.owner(), repo.name(), query)
|
||||
.await?;
|
||||
for page in pages {
|
||||
let title = page
|
||||
.title
|
||||
.as_deref()
|
||||
.ok_or_eyre("page does not have title")?;
|
||||
println!("{bullet} {title}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue