From 1bf0eec41f4378104ca4321c46edf5088840e79c Mon Sep 17 00:00:00 2001 From: thek4n Date: Tue, 24 Mar 2026 19:24:43 +0300 Subject: [PATCH] feat(random): flag --random to open browser on random note --- .pre-commit-config.yaml | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 15 +++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 779a10b..5554cf0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,6 +41,6 @@ repos: - id: check-todos # [NOGREP] name: check-todos # [NOGREP] language: system - entry: sh -c "! grep --color=always --binary-files=without-match --dereference-recursive --exclude-dir='notes' --exclude-dir='node_modules' --exclude-dir='.git' --exclude='.pre-commit-config.yaml' --exclude-dir='venv' 'TODO'" # [NOGREP] + entry: sh -c "! grep --color=always --binary-files=without-match --dereference-recursive --exclude-dir='notes' --exclude-dir='target' --exclude-dir='node_modules' --exclude-dir='.git' --exclude='.pre-commit-config.yaml' --exclude-dir='venv' 'TODO'" # [NOGREP] pass_filenames: false always_run: true diff --git a/Cargo.lock b/Cargo.lock index bd48fa6..02f4f59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,7 +982,7 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "mdpreview" -version = "0.2.1" +version = "0.3.0" dependencies = [ "askama", "askama_axum", diff --git a/Cargo.toml b/Cargo.toml index ddcc238..157e0d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mdpreview" -version = "0.2.1" +version = "0.3.0" edition = "2024" authors = ["Vladislav Kan "] diff --git a/src/main.rs b/src/main.rs index 2d16a9f..5e6d6fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,15 +61,23 @@ pub struct NoteTemplate { #[derive(clap::Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { + /// Host to listen #[arg(long, default_value_t = String::from("localhost"))] host: String, + /// Port to listen #[arg(short, long, default_value_t = 8080)] port: u16, - #[arg(long)] + /// Open browser + #[arg(long, default_value_t = false)] browser: bool, + /// Open browser on random note. Requires flag --broswer + #[arg(long, default_value_t = false, requires = "browser")] + random: bool, + + /// Notes root #[arg()] root: PathBuf, } @@ -131,7 +139,10 @@ async fn main() { println!("Server started on http://{actual_addr}"); if args.browser { - let url = format!("http://{actual_addr}"); + let mut url = format!("http://{actual_addr}"); + if args.random { + url = format!("{url}/random") + } let _ = webbrowser::open(url.as_str()); }