Skip to content

Commit 8f9ee82

Browse files
committed
Adds support + docs for CLI flags (#1)
1 parent a0d99a2 commit 8f9ee82

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

.github/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Changelog
1+
Adds support for command line flags, as well as / instead of environmental variables (fixes #1)

.github/README.md

+61-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ There are several options for running...
1818

1919
### Docker
2020

21+
```bash
22+
docker run -it lissy93/adguardian
23+
```
24+
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.
25+
26+
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`.
27+
2128
### Executable
2229

30+
Head to the [Releases](https://github.com/Lissy93/AdGuardian-Term/releases) tab, and download the executable for your system.
31+
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`)
32+
2333
### Install from Crates.io
2434

2535
### Build from Source
2636

37+
```bash
38+
git clone [email protected]:Lissy93/AdGuardian-Term.git && \
39+
cd AdGuardian-Term && \
40+
make
41+
```
42+
43+
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`
44+
2745
### One-Liner
2846

2947
<details>
@@ -41,14 +59,49 @@ There are several options for running...
4159

4260
## Configuring
4361

44-
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.
62+
The app requires the details of an AdGuard instance to connect to.
63+
This info can be provided either as environmental variables, or passed in as flag parameters.
64+
If any of these fields are missing or incomplete, you'll be prompted to enter a value once the app starts.
4565

46-
The following params are required:
66+
The following params are accepted:
67+
68+
- `ADGUARD_IP` / `--adguard-ip` - The IP address of your local AdGuard Home instance
69+
- `ADGUARD_PORT` / `--adguard-port` - The port that AdGuard is running on
70+
- `ADGUARD_USERNAME` / `--adguard-username` - An AdGuard Home username
71+
- `ADGUARD_PASSWORD` / `--adguard-password` - An AdGuard Home password
72+
73+
<details>
74+
<summary>Examples</summary>
75+
76+
#### With Flags
77+
78+
```bash
79+
./adguardian -- \
80+
--adguard-ip "192.168.180.1" \
81+
--adguard-port "3000" \
82+
--adguard-username "admin" \
83+
--adguard-password "bobs-your-uncle"
84+
```
85+
86+
#### With Env Vars
87+
88+
```bash
89+
ADGUARD_IP="192.168.180.1" ADGUARD_PORT="3000" ADGUARD_USERNAME="admin" ADGUARD_PASSWORD="bobs-your-uncle" ./adguardian
90+
```
91+
92+
#### In Docker
93+
94+
```bash
95+
docker run \
96+
-e "ADGUARD_IP=192.168.180.1" \
97+
-e "ADGUARD_PORT=3000" \
98+
-e "ADGUARD_USERNAME=admin" \
99+
-e "ADGUARD_PASSWORD=bobs-your-uncle" \
100+
-it lissy93/adguardian
101+
```
102+
103+
</details>
47104

48-
- `ADGUARD_IP` - The IP address of your local AdGuard Home instance
49-
- `ADGUARD_PORT` - The port that AdGuard is running on
50-
- `ADGUARD_USERNAME` - An AdGuard Home username
51-
- `ADGUARD_PASSWORD` - An AdGuard Home password
52105

53106
---
54107

@@ -66,6 +119,8 @@ You'll need Rust installed. Run: `curl --proto '=https' --tlsv1.2 -sSf https://s
66119

67120
Then clone the repo, and cd into it, with: `git clone [email protected]:Lissy93/AdGuardian-Term.git` && `cd AdGuardian-Term`
68121

122+
You can view the full list of availible project commands in the [Makefile](https://github.com/Lissy93/AdGuardian-Term/blob/main/Makefile)
123+
69124
### Run
70125

71126
To build and run the project for development, run `cargo run`

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "adguardian"
3-
version = "0.1.0"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["Alicia Sykes"]
66
description = "A terminal dashboard for monitoring AdGuard Home DNS stats"

src/welcome.rs

+22
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {
8989

9090
let client = Client::new();
9191

92+
// List of available flags, ant their associated env vars
93+
let flags = [
94+
("--adguard-ip", "ADGUARD_IP"),
95+
("--adguard-port", "ADGUARD_PORT"),
96+
("--adguard-username", "ADGUARD_USERNAME"),
97+
("--adguard-password", "ADGUARD_PASSWORD"),
98+
];
99+
100+
// Parse command line arguments
101+
let mut args = std::env::args().peekable();
102+
while let Some(arg) = args.next() {
103+
for &(flag, var) in &flags {
104+
if arg == flag {
105+
if let Some(value) = args.peek() {
106+
env::set_var(var, value);
107+
args.next();
108+
}
109+
}
110+
}
111+
}
112+
113+
// If any of the env variables or flags are not yet set, prompt the user to enter them
92114
for &key in &["ADGUARD_IP", "ADGUARD_PORT", "ADGUARD_USERNAME", "ADGUARD_PASSWORD"] {
93115
if env::var(key).is_err() {
94116
println!(

0 commit comments

Comments
 (0)