Skip to content

Commit

Permalink
Adds support + docs for CLI flags (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed May 28, 2023
1 parent a0d99a2 commit 8f9ee82
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Changelog
Adds support for command line flags, as well as / instead of environmental variables (fixes #1)
67 changes: 61 additions & 6 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<details>
Expand All @@ -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

<details>
<summary>Examples</summary>

#### 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
```

</details>

- `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

---

Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
22 changes: 22 additions & 0 deletions src/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {

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!(
Expand Down

0 comments on commit 8f9ee82

Please sign in to comment.