diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 825c32f..d8501fb 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1 +1 @@ -# Changelog +Adds support for command line flags, as well as / instead of environmental variables (fixes #1) diff --git a/.github/README.md b/.github/README.md index 668903b..afa4702 100644 --- a/.github/README.md +++ b/.github/README.md @@ -18,12 +18,30 @@ There are several options for running... ### Docker +```bash +docker run -it lissy93/adguardian +``` +You may also pass in your AdGuard info with env vars (using `-e`), see the [Configuring](#configuring) section for an example, and list of availible config params. + +If you experience issues with DockerHub, or would rather use a different registry, the image is also available via GHCR - just replace the image name with: `ghcr.io/lissy93/adguardian`. Alternatively, if you'd like to build it yourself from source, you can do so with `docker buildx build -t adguardian .` then run it with `docker run -it adguardian`. + ### Executable +Head to the [Releases](https://github.com/Lissy93/AdGuardian-Term/releases) tab, and download the executable for your system. +Then, just run it by either double-clicking on it, or for Linux/Mac users, by running `./adguardian-linux` from the command line (don't forget to make it executable first with `chmod +x adguardian-linux`) + ### Install from Crates.io ### Build from Source +```bash +git clone git@github.com:Lissy93/AdGuardian-Term.git && \ +cd AdGuardian-Term && \ +make +``` + +You'll need `git`, `cargo` and `make` (see [here](#development) for installation notes). You can also run the cargo commands defined in the Makefile directly, e.g. `cargo run` + ### One-Liner
@@ -41,14 +59,49 @@ There are several options for running... ## Configuring -The app requires the details of an AdGuard instance to connect to. This info can be provided either as environmental variables, or passed in as flag parameters. If any of these fields are missing or incomplete, you'll be prompted to enter a value once the app starts. +The app requires the details of an AdGuard instance to connect to. +This info can be provided either as environmental variables, or passed in as flag parameters. +If any of these fields are missing or incomplete, you'll be prompted to enter a value once the app starts. -The following params are required: +The following params are accepted: + +- `ADGUARD_IP` / `--adguard-ip` - The IP address of your local AdGuard Home instance +- `ADGUARD_PORT` / `--adguard-port` - The port that AdGuard is running on +- `ADGUARD_USERNAME` / `--adguard-username` - An AdGuard Home username +- `ADGUARD_PASSWORD` / `--adguard-password` - An AdGuard Home password + +
+Examples + +#### With Flags + +```bash +./adguardian -- \ + --adguard-ip "192.168.180.1" \ + --adguard-port "3000" \ + --adguard-username "admin" \ + --adguard-password "bobs-your-uncle" +``` + +#### With Env Vars + +```bash +ADGUARD_IP="192.168.180.1" ADGUARD_PORT="3000" ADGUARD_USERNAME="admin" ADGUARD_PASSWORD="bobs-your-uncle" ./adguardian +``` + +#### In Docker + +```bash +docker run \ + -e "ADGUARD_IP=192.168.180.1" \ + -e "ADGUARD_PORT=3000" \ + -e "ADGUARD_USERNAME=admin" \ + -e "ADGUARD_PASSWORD=bobs-your-uncle" \ + -it lissy93/adguardian +``` + +
-- `ADGUARD_IP` - The IP address of your local AdGuard Home instance -- `ADGUARD_PORT` - The port that AdGuard is running on -- `ADGUARD_USERNAME` - An AdGuard Home username -- `ADGUARD_PASSWORD` - An AdGuard Home password --- @@ -66,6 +119,8 @@ You'll need Rust installed. Run: `curl --proto '=https' --tlsv1.2 -sSf https://s Then clone the repo, and cd into it, with: `git clone git@github.com:Lissy93/AdGuardian-Term.git` && `cd AdGuardian-Term` +You can view the full list of availible project commands in the [Makefile](https://github.com/Lissy93/AdGuardian-Term/blob/main/Makefile) + ### Run To build and run the project for development, run `cargo run` diff --git a/Cargo.toml b/Cargo.toml index 973dd54..fdb0f68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adguardian" -version = "0.1.0" +version = "0.9.0" edition = "2021" authors = ["Alicia Sykes"] description = "A terminal dashboard for monitoring AdGuard Home DNS stats" diff --git a/src/welcome.rs b/src/welcome.rs index 5ed1bee..3645501 100644 --- a/src/welcome.rs +++ b/src/welcome.rs @@ -89,6 +89,28 @@ pub async fn welcome() -> Result<(), Box> { let client = Client::new(); + // List of available flags, ant their associated env vars + let flags = [ + ("--adguard-ip", "ADGUARD_IP"), + ("--adguard-port", "ADGUARD_PORT"), + ("--adguard-username", "ADGUARD_USERNAME"), + ("--adguard-password", "ADGUARD_PASSWORD"), + ]; + + // Parse command line arguments + let mut args = std::env::args().peekable(); + while let Some(arg) = args.next() { + for &(flag, var) in &flags { + if arg == flag { + if let Some(value) = args.peek() { + env::set_var(var, value); + args.next(); + } + } + } + } + + // If any of the env variables or flags are not yet set, prompt the user to enter them for &key in &["ADGUARD_IP", "ADGUARD_PORT", "ADGUARD_USERNAME", "ADGUARD_PASSWORD"] { if env::var(key).is_err() { println!(