mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
format
This commit is contained in:
parent
7fc2bf7390
commit
5999e1e0b5
2 changed files with 8 additions and 14 deletions
|
@ -41,9 +41,7 @@ async fn main() -> eyre::Result<()> {
|
|||
let host = host.map(|host| Url::parse(&host)).transpose()?;
|
||||
let url = match host {
|
||||
Some(url) => url,
|
||||
None => {
|
||||
repo::RepoInfo::get_current()?.url().clone()
|
||||
}
|
||||
None => repo::RepoInfo::get_current()?.url().clone(),
|
||||
};
|
||||
let name = keys.get_login(&url)?.username();
|
||||
eprintln!("currently signed in to {name}@{url}");
|
||||
|
@ -65,4 +63,3 @@ async fn readline(msg: &str) -> eyre::Result<String> {
|
|||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
|
|
17
src/repo.rs
17
src/repo.rs
|
@ -1,7 +1,7 @@
|
|||
use clap::Subcommand;
|
||||
use eyre::eyre;
|
||||
use forgejo_api::CreateRepoOption;
|
||||
use url::Url;
|
||||
use eyre::eyre;
|
||||
|
||||
pub struct RepoInfo {
|
||||
owner: String,
|
||||
|
@ -14,9 +14,7 @@ impl RepoInfo {
|
|||
let repo = git2::Repository::open(".")?;
|
||||
let url = get_remote(&repo)?;
|
||||
|
||||
let mut path = url
|
||||
.path_segments()
|
||||
.ok_or_else(|| eyre!("bad path"))?;
|
||||
let mut path = url.path_segments().ok_or_else(|| eyre!("bad path"))?;
|
||||
let owner = path
|
||||
.next()
|
||||
.ok_or_else(|| eyre!("path does not have owner name"))?
|
||||
|
@ -26,11 +24,7 @@ impl RepoInfo {
|
|||
.ok_or_else(|| eyre!("path does not have repo name"))?;
|
||||
let name = name.strip_suffix(".git").unwrap_or(name).to_string();
|
||||
|
||||
let repo_info = RepoInfo {
|
||||
owner,
|
||||
name,
|
||||
url,
|
||||
};
|
||||
let repo_info = RepoInfo { owner, name, url };
|
||||
Ok(repo_info)
|
||||
}
|
||||
pub fn owner(&self) -> &str {
|
||||
|
@ -47,7 +41,10 @@ impl RepoInfo {
|
|||
|
||||
pub fn host_url(&self) -> Url {
|
||||
let mut url = self.url.clone();
|
||||
url.path_segments_mut().expect("invalid url: cannot be a base").pop().pop();
|
||||
url.path_segments_mut()
|
||||
.expect("invalid url: cannot be a base")
|
||||
.pop()
|
||||
.pop();
|
||||
url
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue