Add an --open flag to the create command to open the new ticket in a browser

This commit is contained in:
Daan Boerlage 2025-01-21 17:00:32 +01:00
parent f5e31c3a73
commit 63b1f33a0a
Signed by: daan
GPG key ID: FCE070E1E4956606
5 changed files with 46 additions and 3 deletions

31
Cargo.lock generated
View file

@ -820,6 +820,25 @@ version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" 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]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.1" version = "1.70.1"
@ -840,6 +859,7 @@ dependencies = [
"config", "config",
"directories", "directories",
"gray_matter", "gray_matter",
"open",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
@ -977,6 +997,17 @@ version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" 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]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.68" version = "0.10.68"

View file

@ -15,3 +15,4 @@ config = "0.15"
directories = "6.0" directories = "6.0"
tempfile = "3.8" tempfile = "3.8"
gray_matter = { version = "0.2", default-features = false, features = ["toml"] } gray_matter = { version = "0.2", default-features = false, features = ["toml"] }
open = "5.2"

View file

@ -14,6 +14,9 @@ pub enum Commands {
#[arg(long)] #[arg(long)]
project: Option<String>, project: Option<String>,
#[arg(long)]
open: bool,
#[arg(value_name = "MARKDOWN_FILE")] #[arg(value_name = "MARKDOWN_FILE")]
markdown_file: Option<PathBuf>, markdown_file: Option<PathBuf>,
}, },

View file

@ -340,6 +340,7 @@ async fn update_issue_status(
pub async fn create( pub async fn create(
project: Option<String>, project: Option<String>,
open: bool,
markdown_file: Option<PathBuf>, markdown_file: Option<PathBuf>,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?; let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?;
@ -386,8 +387,14 @@ pub async fn create(
let response = let response =
create_jira_issue(&config, &selected_project, &title, &description, &metadata).await?; 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!("Successfully created ticket: {}", response.key);
println!("URL: {}/browse/{}", config.url, response.key); println!("URL: {}", url);
if open {
open::that(url)?;
}
Ok(()) Ok(())
} }

View file

@ -13,8 +13,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match cli.command { match cli.command {
Commands::Create { Commands::Create {
project, project,
open,
markdown_file, 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::List { json } => cmd::list::list(json).await?,
Commands::Init { url, email, token } => { Commands::Init { url, email, token } => {
JiraConfig::init(url, email, token).await?; JiraConfig::init(url, email, token).await?;