diff --git a/README.md b/README.md index 0e815c5..fb11f91 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Commands: clone Clones a Git repository to local delete Deletes a repository from local init Initialises a Git repository in local + open Opens a repository in an application path Prints the path to root, owner, or a repository profile Manages profiles to use in repositories shell Writes a shell script to extend ghr features diff --git a/src/cmd/delete.rs b/src/cmd/delete.rs index 9ae96a3..8537a0a 100644 --- a/src/cmd/delete.rs +++ b/src/cmd/delete.rs @@ -16,7 +16,7 @@ use crate::url::Url; #[derive(Debug, Parser)] pub struct Cmd { - /// URL or pattern of the repository to clone. + /// URL or pattern of the repository to delete. repo: String, } diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index a76a029..4e1ea59 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -2,6 +2,7 @@ mod cd; mod clone; mod delete; mod init; +mod open; mod path; mod profile; mod shell; @@ -19,6 +20,8 @@ pub enum Action { Delete(delete::Cmd), /// Initialises a Git repository in local. Init(init::Cmd), + /// Opens a repository in an application. + Open(open::Cmd), /// Prints the path to root, owner, or a repository. Path(path::Cmd), /// Manages profiles to use in repositories. @@ -41,6 +44,7 @@ impl Cli { Clone(cmd) => cmd.run().await, Delete(cmd) => cmd.run().await, Init(cmd) => cmd.run(), + Open(cmd) => cmd.run(), Path(cmd) => cmd.run(), Profile(cmd) => cmd.run(), Shell(cmd) => cmd.run(), diff --git a/src/cmd/open.rs b/src/cmd/open.rs new file mode 100644 index 0000000..16f86ea --- /dev/null +++ b/src/cmd/open.rs @@ -0,0 +1,33 @@ +use std::path::PathBuf; +use std::str::FromStr; + +use anyhow::Result; +use clap::Parser; + +use crate::config::Config; +use crate::path::Path; +use crate::root::Root; +use crate::url::Url; + +#[derive(Debug, Parser)] +pub struct Cmd { + /// URL or pattern of the repository to open application in. + repo: String, + + /// Name of the application entry. + application: String, +} + +impl Cmd { + pub fn run(self) -> Result<()> { + let root = Root::find()?; + let config = Config::load_from(&root)?; + + let url = Url::from_str(&self.repo)?; + let path = PathBuf::from(Path::resolve(&root, &url)); + + config.applications.open(&self.application, path)?; + + Ok(()) + } +}