Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
fix works
Browse files Browse the repository at this point in the history
  • Loading branch information
xortive committed Aug 5, 2019
1 parent d4be43d commit 3269f4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ pub fn set_file_mode(file: &PathBuf) {
.expect("could not set permissions on file");
}

pub fn global_config(email: &str, api_key: &str) -> Result<(), failure::Error> {
let s = GlobalUser {
email: email.to_string(),
api_key: api_key.to_string(),
};
pub fn global_config(email: String, api_key: String) -> Result<(), failure::Error> {
let s = GlobalUser { email, api_key };

let toml = toml::to_string(&s)?;

Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ fn run() -> Result<(), failure::Error> {

if let Some(_matches) = matches.subcommand_matches("config") {
println!("Enter email: ");
let email: String = read!("{}\n");
let mut email: String = read!("{}\n");
email.truncate(email.trim_end().len());
println!("Enter api key: ");
let api_key: String = read!("{}\n");
let mut api_key: String = read!("{}\n");
api_key.truncate(api_key.trim_end().len());

commands::global_config(&email, &api_key)?;
commands::global_config(email, api_key)?;
} else if let Some(matches) = matches.subcommand_matches("generate") {
let name = matches.value_of("name").unwrap_or("worker");
let project_type = match matches.value_of("type") {
Expand Down
28 changes: 24 additions & 4 deletions tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ use std::io::prelude::*;
use std::process::{Child, Command, Stdio};

#[test]
fn it_generates_the_config() {
fn it_generates_the_config_unix_eol() {
generate_config_with("\n");
}

#[test]
fn it_generates_the_config_windows_eol() {
generate_config_with("\r\n");
}

fn generate_config_with(eol: &str) {
let fake_home_dir = env::current_dir()
.expect("could not retrieve cwd")
.join(".it_generates_the_config");
.join(format!(".it_generates_the_config_{}", random_chars(5)));
let cmd = config_with_wrangler_home(fake_home_dir.to_str().unwrap());
let mut stdin = cmd.stdin.unwrap();

write!(stdin, "[email protected]\n").unwrap();
write!(stdin, "apikeythisissecretandlong\n").unwrap();
write!(stdin, "[email protected]{}", eol).unwrap();
write!(stdin, "apikeythisissecretandlong{}", eol).unwrap();

let mut buffer = "".to_string();
let mut stdout = cmd.stdout.expect("stdout");
Expand Down Expand Up @@ -57,3 +66,14 @@ fn config_with_wrangler_home(home_dir: &str) -> Child {
.spawn()
.unwrap()
}

fn random_chars(n: usize) -> String {
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::iter;
let mut rng = thread_rng();
iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
.take(n)
.collect()
}

0 comments on commit 3269f4c

Please sign in to comment.