Skip to content

Commit

Permalink
Add hyperlink extension, hyperlink the version on install command…
Browse files Browse the repository at this point in the history
… to the release page
  • Loading branch information
catuhana committed Jul 2, 2024
1 parent d9de856 commit 6720819
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fmt, str};
use clap::Args;

use super::NueCommand;
use crate::types;
use crate::{exts::HyperlinkExt, types};

#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum VersionInputs {
Expand Down Expand Up @@ -64,16 +64,19 @@ impl NueCommand for CommandArguments {

match latest_release {
Some(release) => {
let version_str = format!("v{}", release.version);
let branch_name = match release_branch {
"latest" => "current",
"LTS" => release_branch,
_ => release_branch,
};

println!(
"Installing version v{} from `{}` branch",
release.version,
if release_branch == "latest" {
"current"
} else if release_branch == "LTS" {
release_branch
} else {
release_branch
}
"Installing version {} from `{}` branch",
version_str.hyperlink(format!(
"https://github.com/nodejs/node/releases/tag/{version_str}"
)),
branch_name
)
}
None => {
Expand Down
16 changes: 16 additions & 0 deletions src/exts/hyperlink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub trait Ext {
fn hyperlink(&self, url: impl ToString) -> String;
}

impl<T> Ext for T
where
T: ToString,
{
fn hyperlink(&self, url: impl ToString) -> String {
format!(
"\u{001B}]8;;{}\u{0007}{}\u{001B}]8;;\u{0007}",
url.to_string(),
self.to_string()
)
}
}
3 changes: 3 additions & 0 deletions src/exts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod hyperlink;

pub use hyperlink::Ext as HyperlinkExt;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;
use cli::NueCommand;

mod cli;
mod exts;
mod types;

fn main() -> anyhow::Result<()> {
Expand Down

0 comments on commit 6720819

Please sign in to comment.