Impl passing password via file
This commit is contained in:
parent
d1590bee0a
commit
e0be69df81
1 changed files with 22 additions and 1 deletions
23
src/main.rs
23
src/main.rs
|
@ -9,6 +9,8 @@ use ggez::event::winit_event::{ElementState, KeyboardInput, ModifiersState};
|
||||||
use ggez::event::{self, ControlFlow, EventHandler};
|
use ggez::event::{self, ControlFlow, EventHandler};
|
||||||
use ggez::input::keyboard::{self, KeyInput};
|
use ggez::input::keyboard::{self, KeyInput};
|
||||||
use ggez::{ContextBuilder, GameError};
|
use ggez::{ContextBuilder, GameError};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
@ -35,6 +37,8 @@ pub struct Opt {
|
||||||
disable_show_filename: bool,
|
disable_show_filename: bool,
|
||||||
#[structopt(long = "pprompt", help = "input password via prompt")]
|
#[structopt(long = "pprompt", help = "input password via prompt")]
|
||||||
enable_prompt_password: bool,
|
enable_prompt_password: bool,
|
||||||
|
#[structopt(long = "pfile", help = "read password from file")]
|
||||||
|
password_file: Option<PathBuf>,
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "no-scale-fill",
|
long = "no-scale-fill",
|
||||||
help = "don't scale-fill the album art to the window"
|
help = "don't scale-fill the album art to the window"
|
||||||
|
@ -58,9 +62,26 @@ pub struct Opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), String> {
|
fn main() -> Result<(), String> {
|
||||||
let opt = Opt::from_args();
|
let mut opt = Opt::from_args();
|
||||||
println!("Got host addr == {}, port == {}", opt.host, opt.port);
|
println!("Got host addr == {}, port == {}", opt.host, opt.port);
|
||||||
|
|
||||||
|
// Read password from file if exists, error otherwise.
|
||||||
|
if let Some(psswd_file_path) = opt.password_file.as_ref() {
|
||||||
|
let mut file = File::open(psswd_file_path).expect("pfile/password_file should exist");
|
||||||
|
let mut content: String = String::new();
|
||||||
|
|
||||||
|
file.read_to_string(&mut content)
|
||||||
|
.expect("Should be able to read from pfile/password_file");
|
||||||
|
|
||||||
|
if content.ends_with("\r\n") {
|
||||||
|
content.truncate(content.len() - 2);
|
||||||
|
} else if content.ends_with('\n') {
|
||||||
|
content.truncate(content.len() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.password = Some(content);
|
||||||
|
}
|
||||||
|
|
||||||
let (mut ctx, event_loop) = ContextBuilder::new("mpd_info_screen", "Stephen Seo")
|
let (mut ctx, event_loop) = ContextBuilder::new("mpd_info_screen", "Stephen Seo")
|
||||||
.window_setup(WindowSetup {
|
.window_setup(WindowSetup {
|
||||||
title: "mpd info screen".into(),
|
title: "mpd info screen".into(),
|
||||||
|
|
Loading…
Reference in a new issue