This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: use stdin instead of arguments
This changes the way `wrangler config` works, previously both the email and the api_key were passed as arguments which would be captured by the terminal history. When launching the command it will prompt for an email, once stdin receive a line it will prompt for the api_key. Both lines are values and will be stored in the config.
- Loading branch information
Showing
4 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use assert_cmd::prelude::*; | ||
use std::env; | ||
use std::fs; | ||
use std::io::prelude::*; | ||
use std::process::{Child, Command, Stdio}; | ||
|
||
#[test] | ||
fn it_generates_the_config() { | ||
let fake_home_dir = env::current_dir() | ||
.expect("could not retrieve cwd") | ||
.join(".it_generates_the_config"); | ||
let cmd = config_with_home(fake_home_dir.to_str().unwrap()); | ||
let mut stdin = cmd.stdin.unwrap(); | ||
|
||
write!(stdin, "a\n").unwrap(); // email | ||
write!(stdin, "b\n").unwrap(); // api_key | ||
|
||
let mut buffer = "".to_string(); | ||
let mut stdout = cmd.stdout.unwrap(); | ||
stdout | ||
.read_to_string(&mut buffer) | ||
.expect("could not read output"); | ||
assert!(buffer.contains("Enter email: \nEnter api key: \n Successfully configured.")); | ||
|
||
let config_file = fake_home_dir | ||
.join(".wrangler") | ||
.join("config") | ||
.join("default.toml"); | ||
|
||
let config = fs::read_to_string(&config_file) | ||
.expect(&format!("could not read config at {:?}", &config_file)); | ||
assert_eq!( | ||
config, | ||
r#"email = "a" | ||
api_key = "b" | ||
"# | ||
); | ||
|
||
fs::remove_dir_all(&fake_home_dir).expect("could not delete dir"); | ||
} | ||
|
||
fn config_with_home(home_dir: &str) -> Child { | ||
let mut wrangler = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); | ||
wrangler | ||
.arg("config") | ||
.stdin(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.env("HOME", home_dir) | ||
.spawn() | ||
.unwrap() | ||
} |