mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-09-20 08:05:04 +02:00
feat: wiki browse
This commit is contained in:
parent
a756d1da57
commit
de144f29e6
1 changed files with 22 additions and 2 deletions
24
src/wiki.rs
24
src/wiki.rs
|
@ -27,6 +27,11 @@ pub enum WikiSubcommand {
|
||||||
repo: Option<RepoArg>,
|
repo: Option<RepoArg>,
|
||||||
page: String,
|
page: String,
|
||||||
},
|
},
|
||||||
|
Browse {
|
||||||
|
#[clap(long, short)]
|
||||||
|
repo: Option<RepoArg>,
|
||||||
|
page: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WikiCommand {
|
impl WikiCommand {
|
||||||
|
@ -40,6 +45,7 @@ impl WikiCommand {
|
||||||
match self.command {
|
match self.command {
|
||||||
Contents { repo: _ } => wiki_contents(&repo, &api).await?,
|
Contents { repo: _ } => wiki_contents(&repo, &api).await?,
|
||||||
View { repo: _, page } => view_wiki_page(&repo, &api, &*page).await?,
|
View { repo: _, page } => view_wiki_page(&repo, &api, &*page).await?,
|
||||||
|
Browse { repo: _, page } => browse_wiki_page(&repo, &api, &*page).await?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -47,14 +53,16 @@ impl WikiCommand {
|
||||||
fn repo(&self) -> Option<&RepoArg> {
|
fn repo(&self) -> Option<&RepoArg> {
|
||||||
use WikiSubcommand::*;
|
use WikiSubcommand::*;
|
||||||
match &self.command {
|
match &self.command {
|
||||||
Contents { repo } | View { repo, .. } => repo.as_ref(),
|
Contents { repo } | View { repo, .. } | Browse { repo, .. } => repo.as_ref(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_repo_error(&self) -> eyre::Error {
|
fn no_repo_error(&self) -> eyre::Error {
|
||||||
use WikiSubcommand::*;
|
use WikiSubcommand::*;
|
||||||
match &self.command {
|
match &self.command {
|
||||||
Contents { repo: _ } | View { .. } => eyre::eyre!("couldn't guess repo"),
|
Contents { repo: _ } | View { .. } | Browse { .. } => {
|
||||||
|
eyre::eyre!("couldn't guess repo")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,3 +112,15 @@ async fn view_wiki_page(repo: &RepoName, api: &Forgejo, page: &str) -> eyre::Res
|
||||||
println!("{}", crate::markdown(&contents));
|
println!("{}", crate::markdown(&contents));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn browse_wiki_page(repo: &RepoName, api: &Forgejo, page: &str) -> eyre::Result<()> {
|
||||||
|
let page = api
|
||||||
|
.repo_get_wiki_page(repo.owner(), repo.name(), page)
|
||||||
|
.await?;
|
||||||
|
let html_url = page
|
||||||
|
.html_url
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_eyre("page does not have html url")?;
|
||||||
|
open::that(html_url.as_str())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue