Add --open flag support to the docs server
This commit is contained in:
Generated
+37
@@ -897,6 +897,25 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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"
|
||||||
@@ -1142,6 +1161,17 @@ version = "1.70.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
|
[[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-probe"
|
name = "openssl-probe"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@@ -1170,6 +1200,12 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pathdiff"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "payphone"
|
name = "payphone"
|
||||||
version = "4.0.0"
|
version = "4.0.0"
|
||||||
@@ -1184,6 +1220,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"notify",
|
"notify",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"open",
|
||||||
"rand",
|
"rand",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"scc",
|
"scc",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ linkify = "0.10.0"
|
|||||||
log = { version = "0.4.27", features = ["serde"] }
|
log = { version = "0.4.27", features = ["serde"] }
|
||||||
notify = "8.2.0"
|
notify = "8.2.0"
|
||||||
once_cell = "1.21.3"
|
once_cell = "1.21.3"
|
||||||
|
open = "5.3.2"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
rand_chacha = { version = "0.9.0", features = ["os_rng"] }
|
rand_chacha = { version = "0.9.0", features = ["os_rng"] }
|
||||||
scc = "2.3.4"
|
scc = "2.3.4"
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ To read the documentation, run
|
|||||||
```shell
|
```shell
|
||||||
$ git clone --branch rewrite https://git.nyeki.dev/payphone/payphone.git
|
$ git clone --branch rewrite https://git.nyeki.dev/payphone/payphone.git
|
||||||
$ cd payphone
|
$ cd payphone
|
||||||
$ cargo run -- docs
|
$ cargo run -- docs --open
|
||||||
```
|
```
|
||||||
|
|||||||
+18
@@ -37,6 +37,14 @@
|
|||||||
//!
|
//!
|
||||||
//! let args = Args::parse();
|
//! let args = Args::parse();
|
||||||
//! ```
|
//! ```
|
||||||
|
//!
|
||||||
|
//! # Running the Bot
|
||||||
|
//!
|
||||||
|
//! To start the bot, run:
|
||||||
|
//!
|
||||||
|
//! ```shell
|
||||||
|
//! $ cargo run -- start [TOKEN]
|
||||||
|
//! ```
|
||||||
|
|
||||||
/// Payphone's argument parser.
|
/// Payphone's argument parser.
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
@@ -130,5 +138,15 @@ pub enum Commands {
|
|||||||
default_value_t = 3000
|
default_value_t = 3000
|
||||||
)]
|
)]
|
||||||
port: u16,
|
port: u16,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short,
|
||||||
|
env = "PAYPHONE_DOCS_OPEN",
|
||||||
|
value_name = "OPEN",
|
||||||
|
default_value_t = false,
|
||||||
|
help = "Open the documentation in the default browser after starting the server."
|
||||||
|
)]
|
||||||
|
open: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-7
@@ -97,7 +97,7 @@
|
|||||||
//! it on changes. To start the documentation server, run the following command:
|
//! it on changes. To start the documentation server, run the following command:
|
||||||
//!
|
//!
|
||||||
//! ```shell
|
//! ```shell
|
||||||
//! $ cargo run -- docs
|
//! $ cargo run -- docs --open
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use std::{net::SocketAddr, path::Path, process::Command, sync::mpsc};
|
use std::{net::SocketAddr, path::Path, process::Command, sync::mpsc};
|
||||||
@@ -150,8 +150,8 @@ pub async fn main() {
|
|||||||
} => {
|
} => {
|
||||||
start(token, database_addr).await;
|
start(token, database_addr).await;
|
||||||
}
|
}
|
||||||
Commands::Docs { port } => {
|
Commands::Docs { port, open } => {
|
||||||
docs(port).await;
|
docs(port, open).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ async fn start(token: String, database_addr: String) {
|
|||||||
bot.run(&token).await.expect("Could not run bot!");
|
bot.run(&token).await.expect("Could not run bot!");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn docs(port: u16) {
|
async fn docs(port: u16, open_on_start: bool) {
|
||||||
log::info!("Compiling documentation...");
|
log::info!("Compiling documentation...");
|
||||||
|
|
||||||
Command::new("cargo")
|
Command::new("cargo")
|
||||||
@@ -247,7 +247,18 @@ async fn docs(port: u16) {
|
|||||||
|
|
||||||
log::info!("Documentation server is running on http://localhost:{port}/");
|
log::info!("Documentation server is running on http://localhost:{port}/");
|
||||||
|
|
||||||
axum::serve(listener, docs)
|
let handle = tokio::spawn(async move {
|
||||||
.await
|
axum::serve(listener, docs)
|
||||||
.expect("Could not start documentation server!");
|
.await
|
||||||
|
.expect("Could not start documentation server!")
|
||||||
|
});
|
||||||
|
|
||||||
|
if open_on_start {
|
||||||
|
match open::that(format!("http://localhost:{port}/")) {
|
||||||
|
Ok(_) => log::info!("Opened documentation in browser!"),
|
||||||
|
Err(e) => log::error!("Failed to open documentation in browser: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.await.expect("Documentation server task failed!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user