Skip to content

Commit

Permalink
Merge branch 'env-password' of https://github.com/herrernst/librespot
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
plietar committed Jan 2, 2016
2 parents e35da9c + 7f8e85f commit 47c6d60
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use librespot::session::{Config, Session};
use librespot::spirc::SpircManager;
use librespot::util::version::version_string;

static PASSWORD_ENV_NAME: &'static str = "SPOTIFY_PASSWORD";

fn usage(program: &str, opts: &Options) -> String {
let brief = format!("Usage: {} [options]", program);
format!("{}", opts.usage(&brief))
Expand Down Expand Up @@ -55,7 +57,9 @@ fn main() {
let name = matches.opt_str("n").unwrap();

let credentials = username.map(|u| {
let password = matches.opt_str("p").unwrap_or_else(|| {
let password = matches.opt_str("p").or_else(|| {
std::env::var(PASSWORD_ENV_NAME).ok()
}).unwrap_or_else(|| {
print!("Password: ");
stdout().flush().unwrap();
read_password().unwrap()
Expand All @@ -64,6 +68,8 @@ fn main() {
(u, password)
});

std::env::remove_var(PASSWORD_ENV_NAME);

let config = Config {
application_key: appkey,
user_agent: version_string(),
Expand Down

0 comments on commit 47c6d60

Please sign in to comment.