feat(random): flag --random to open browser on random note
This commit is contained in:
parent
e3dc697e42
commit
1bf0eec41f
@ -41,6 +41,6 @@ repos:
|
|||||||
- id: check-todos # [NOGREP]
|
- id: check-todos # [NOGREP]
|
||||||
name: check-todos # [NOGREP]
|
name: check-todos # [NOGREP]
|
||||||
language: system
|
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
|
pass_filenames: false
|
||||||
always_run: true
|
always_run: true
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -982,7 +982,7 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mdpreview"
|
name = "mdpreview"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"askama_axum",
|
"askama_axum",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mdpreview"
|
name = "mdpreview"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Vladislav Kan <thek4n@yandex.ru>"]
|
authors = ["Vladislav Kan <thek4n@yandex.ru>"]
|
||||||
|
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@ -61,15 +61,23 @@ pub struct NoteTemplate {
|
|||||||
#[derive(clap::Parser, Debug)]
|
#[derive(clap::Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Host to listen
|
||||||
#[arg(long, default_value_t = String::from("localhost"))]
|
#[arg(long, default_value_t = String::from("localhost"))]
|
||||||
host: String,
|
host: String,
|
||||||
|
|
||||||
|
/// Port to listen
|
||||||
#[arg(short, long, default_value_t = 8080)]
|
#[arg(short, long, default_value_t = 8080)]
|
||||||
port: u16,
|
port: u16,
|
||||||
|
|
||||||
#[arg(long)]
|
/// Open browser
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
browser: bool,
|
browser: bool,
|
||||||
|
|
||||||
|
/// Open browser on random note. Requires flag --broswer
|
||||||
|
#[arg(long, default_value_t = false, requires = "browser")]
|
||||||
|
random: bool,
|
||||||
|
|
||||||
|
/// Notes root
|
||||||
#[arg()]
|
#[arg()]
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
}
|
}
|
||||||
@ -131,7 +139,10 @@ async fn main() {
|
|||||||
println!("Server started on http://{actual_addr}");
|
println!("Server started on http://{actual_addr}");
|
||||||
|
|
||||||
if args.browser {
|
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());
|
let _ = webbrowser::open(url.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user