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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-14
@@ -22,19 +22,19 @@
|
|||||||
//!
|
//!
|
||||||
//! To stop the database cluster at any time, run `docker compose down`. To stop it and delete the
|
//! To stop the database cluster at any time, run `docker compose down`. To stop it and delete the
|
||||||
//! volumes (resetting the database), run `docker compose down -v`.
|
//! volumes (resetting the database), run `docker compose down -v`.
|
||||||
//!
|
//!
|
||||||
//! Before booting up scylla, you'll need to set the `aio-max-nr` kernel parameter to `1048576` or
|
//! Before booting up scylla, you'll need to set the `aio-max-nr` kernel parameter to `1048576` or
|
||||||
//! higher. You can check [Scylla's documentation](https://hub.docker.com/r/scylladb/scylla) for
|
//! higher. You can check [Scylla's documentation](https://hub.docker.com/r/scylladb/scylla) for
|
||||||
//! the math of the value at which you'll need to set the parameter. In linux, you can set it by
|
//! the math of the value at which you'll need to set the parameter. In linux, you can set it by
|
||||||
//! running:
|
//! running:
|
||||||
//!
|
//!
|
||||||
//! ```shell
|
//! ```shell
|
||||||
//! $ sudo sysctl -w fs.aio-max-nr=1048576
|
//! $ sudo sysctl -w fs.aio-max-nr=1048576
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! That will set it up for your current session. To make it persistent across reboots, add the
|
//! That will set it up for your current session. To make it persistent across reboots, add the
|
||||||
//! following to your `/etc/sysctl.conf` file (or to a new file in `/etc/sysctl.d/`):
|
//! following to your `/etc/sysctl.conf` file (or to a new file in `/etc/sysctl.d/`):
|
||||||
//!
|
//!
|
||||||
//! ```conf
|
//! ```conf
|
||||||
//! fs.aio-max-nr = 1048576
|
//! fs.aio-max-nr = 1048576
|
||||||
//! ```
|
//! ```
|
||||||
@@ -90,14 +90,14 @@
|
|||||||
//! consistency and readability.
|
//! consistency and readability.
|
||||||
//!
|
//!
|
||||||
//! More documentation about each group can be found in the respective submodule's documentation.
|
//! More documentation about each group can be found in the respective submodule's documentation.
|
||||||
//!
|
//!
|
||||||
//! # Documentation Server
|
//! # Documentation Server
|
||||||
//!
|
//!
|
||||||
//! Payphone has a built-in documentation server that serves the project's documentation and refreshes
|
//! Payphone has a built-in documentation server that serves the project's documentation and refreshes
|
||||||
//! 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