From 63b1f33a0ab451b2f119ebc5c40da11831dc8cd6 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Tue, 21 Jan 2025 17:00:32 +0100 Subject: [PATCH] Add an --open flag to the create command to open the new ticket in a browser --- Cargo.lock | 31 +++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- src/cli.rs | 3 +++ src/cmd/create.rs | 9 ++++++++- src/main.rs | 3 ++- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b0621c..8207c42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -820,6 +820,25 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -840,6 +859,7 @@ dependencies = [ "config", "directories", "gray_matter", + "open", "reqwest", "serde", "serde_json", @@ -977,6 +997,17 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "open" +version = "5.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2483562e62ea94312f3576a7aca397306df7990b8d89033e18766744377ef95" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + [[package]] name = "openssl" version = "0.10.68" diff --git a/Cargo.toml b/Cargo.toml index 55a8bd7..e4712c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ toml = "0.8" config = "0.15" directories = "6.0" tempfile = "3.8" -gray_matter = { version = "0.2", default-features = false, features = ["toml"] } \ No newline at end of file +gray_matter = { version = "0.2", default-features = false, features = ["toml"] } +open = "5.2" \ No newline at end of file diff --git a/src/cli.rs b/src/cli.rs index c75bc73..30e0376 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,6 +14,9 @@ pub enum Commands { #[arg(long)] project: Option, + #[arg(long)] + open: bool, + #[arg(value_name = "MARKDOWN_FILE")] markdown_file: Option, }, diff --git a/src/cmd/create.rs b/src/cmd/create.rs index 1ec7458..8996c30 100644 --- a/src/cmd/create.rs +++ b/src/cmd/create.rs @@ -340,6 +340,7 @@ async fn update_issue_status( pub async fn create( project: Option, + open: bool, markdown_file: Option, ) -> Result<(), Box> { let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?; @@ -386,8 +387,14 @@ pub async fn create( let response = create_jira_issue(&config, &selected_project, &title, &description, &metadata).await?; + let url = format!("{}/browse/{}", config.url, response.key); + println!("Successfully created ticket: {}", response.key); - println!("URL: {}/browse/{}", config.url, response.key); + println!("URL: {}", url); + + if open { + open::that(url)?; + } Ok(()) } diff --git a/src/main.rs b/src/main.rs index 0e8d145..cc526c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,9 @@ async fn main() -> Result<(), Box> { match cli.command { Commands::Create { project, + open, markdown_file, - } => cmd::create::create(project, markdown_file).await?, + } => cmd::create::create(project, open, markdown_file).await?, Commands::List { json } => cmd::list::list(json).await?, Commands::Init { url, email, token } => { JiraConfig::init(url, email, token).await?;