summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-08-08 00:19:57 +0200
committerCyborus <cyborus@cyborus.xyz>2024-08-08 01:35:51 +0200
commitde144f29e663d5d1aaebbf608cf794dd2c3323c9 (patch)
tree322296d2f3c049cd17f050a87a3a9aaf454937c9
parentfeat: `wiki view` (diff)
downloadforgejo-cli-de144f29e663d5d1aaebbf608cf794dd2c3323c9.tar.xz
forgejo-cli-de144f29e663d5d1aaebbf608cf794dd2c3323c9.zip
feat: `wiki browse`
-rw-r--r--src/wiki.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/wiki.rs b/src/wiki.rs
index f5724df..4aff76c 100644
--- a/src/wiki.rs
+++ b/src/wiki.rs
@@ -27,6 +27,11 @@ pub enum WikiSubcommand {
repo: Option<RepoArg>,
page: String,
},
+ Browse {
+ #[clap(long, short)]
+ repo: Option<RepoArg>,
+ page: String,
+ },
}
impl WikiCommand {
@@ -40,6 +45,7 @@ impl WikiCommand {
match self.command {
Contents { repo: _ } => wiki_contents(&repo, &api).await?,
View { repo: _, page } => view_wiki_page(&repo, &api, &*page).await?,
+ Browse { repo: _, page } => browse_wiki_page(&repo, &api, &*page).await?,
}
Ok(())
}
@@ -47,14 +53,16 @@ impl WikiCommand {
fn repo(&self) -> Option<&RepoArg> {
use WikiSubcommand::*;
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 {
use WikiSubcommand::*;
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));
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(())
+}