Skip to content

Commit b7c0344

Browse files
committed
URL and credentials from env for stalwart-cli (closes #88)
1 parent 5c1a0f7 commit b7c0344

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

crates/cli/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ pub mod modules;
4444
#[tokio::main]
4545
async fn main() -> std::io::Result<()> {
4646
let args = Cli::parse();
47+
let url = args
48+
.url
49+
.or_else(|| std::env::var("URL").ok())
50+
.unwrap_or_else(|| {
51+
eprintln!("No URL specified. Use --url or set the URL environment variable.");
52+
std::process::exit(1);
53+
});
4754
let client = Client {
4855
credentials: if let Some(credentials) = args.credentials {
4956
parse_credentials(&credentials)
57+
} else if let Ok(credentials) = std::env::var("CREDENTIALS") {
58+
parse_credentials(&credentials)
5059
} else {
5160
let credentials = rpassword::prompt_password(
5261
"\nEnter administrator credentials or press [ENTER] to use OAuth: ",
@@ -55,11 +64,11 @@ async fn main() -> std::io::Result<()> {
5564
if !credentials.is_empty() {
5665
parse_credentials(&credentials)
5766
} else {
58-
oauth(&args.url).await
67+
oauth(&url).await
5968
}
6069
},
6170
timeout: args.timeout,
62-
url: args.url,
71+
url,
6372
};
6473

6574
match args.command {

crates/cli/src/modules/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Cli {
3434
pub command: Commands,
3535
/// Server base URL
3636
#[clap(short, long)]
37-
pub url: String,
37+
pub url: Option<String>,
3838
/// Authentication credentials
3939
#[clap(short, long)]
4040
pub credentials: Option<String>,
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/bin/bash
22

3-
cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret domain create example.org
4-
cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org
5-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create jane abcde -d "Jane Doe" -a jane@example.org
6-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a bill@example.org
7-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create sales -d "Sales Department"
8-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create support -d "Technical Support"
9-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-to-group john sales support
10-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account remove-from-group john support
11-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-email jane jane.doe@example.org
12-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list create everyone everyone@example.org
13-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list add-members everyone jane john bill
14-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account list
15-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format mbox john _ignore/dovecot-crlf
16-
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format maildir john /var/mail/john
3+
URL="https://127.0.0.1:443"
4+
CREDENTIALS="admin:secret"
5+
6+
cargo run -p stalwart-cli -- domain create example.org
7+
cargo run -p stalwart-cli -- account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org
8+
#cargo run -p stalwart-cli -- account create jane abcde -d "Jane Doe" -a jane@example.org
9+
#cargo run -p stalwart-cli -- account create bill xyz12 -d "Bill Foobar" -a bill@example.org
10+
#cargo run -p stalwart-cli -- group create sales -d "Sales Department"
11+
#cargo run -p stalwart-cli -- group create support -d "Technical Support"
12+
#cargo run -p stalwart-cli -- account add-to-group john sales support
13+
#cargo run -p stalwart-cli -- account remove-from-group john support
14+
#cargo run -p stalwart-cli -- account add-email jane jane.doe@example.org
15+
#cargo run -p stalwart-cli -- list create everyone everyone@example.org
16+
#cargo run -p stalwart-cli -- list add-members everyone jane john bill
17+
#cargo run -p stalwart-cli -- account list
18+
#cargo run -p stalwart-cli -- import messages --format mbox john _ignore/dovecot-crlf
19+
#cargo run -p stalwart-cli -- import messages --format maildir john /var/mail/john

0 commit comments

Comments
 (0)