mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge branch 'env-password' of https://github.com/herrernst/librespot into master
This commit is contained in:
commit
47c6d60b12
1 changed files with 7 additions and 1 deletions
|
@ -16,6 +16,8 @@ use librespot::session::{Config, Session};
|
||||||
use librespot::spirc::SpircManager;
|
use librespot::spirc::SpircManager;
|
||||||
use librespot::util::version::version_string;
|
use librespot::util::version::version_string;
|
||||||
|
|
||||||
|
static PASSWORD_ENV_NAME: &'static str = "SPOTIFY_PASSWORD";
|
||||||
|
|
||||||
fn usage(program: &str, opts: &Options) -> String {
|
fn usage(program: &str, opts: &Options) -> String {
|
||||||
let brief = format!("Usage: {} [options]", program);
|
let brief = format!("Usage: {} [options]", program);
|
||||||
format!("{}", opts.usage(&brief))
|
format!("{}", opts.usage(&brief))
|
||||||
|
@ -55,7 +57,9 @@ fn main() {
|
||||||
let name = matches.opt_str("n").unwrap();
|
let name = matches.opt_str("n").unwrap();
|
||||||
|
|
||||||
let credentials = username.map(|u| {
|
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: ");
|
print!("Password: ");
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
read_password().unwrap()
|
read_password().unwrap()
|
||||||
|
@ -64,6 +68,8 @@ fn main() {
|
||||||
(u, password)
|
(u, password)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
std::env::remove_var(PASSWORD_ENV_NAME);
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
application_key: appkey,
|
application_key: appkey,
|
||||||
user_agent: version_string(),
|
user_agent: version_string(),
|
||||||
|
|
Loading…
Reference in a new issue