diff options
| author | Teddy Wing | 2017-05-07 14:14:17 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-05-07 14:42:47 +0200 | 
| commit | 69dd2a7a23d1d71c50a91f5779db6f0480106cd8 (patch) | |
| tree | cc0c54a1ff4632ccaa4ee2b86b8932d1533a27b9 | |
| parent | 8043ad6e42611a68e3a572c4657285030d51e74e (diff) | |
| download | HearURL-69dd2a7a23d1d71c50a91f5779db6f0480106cd8.tar.bz2 | |
open_stream(): Remove hard-coded browser & port
Instead get these from function arguments, which in turn get fed from
the command line arguments passed by the user.
| -rw-r--r-- | src/main.rs | 10 | 
1 files changed, 6 insertions, 4 deletions
| diff --git a/src/main.rs b/src/main.rs index e6e7f61..60780fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,10 @@ use std::process::Command;  const DEFAULT_PORT: u16 = 37705; -fn open_stream() -> io::Result<()> { -    let listener = TcpListener::bind("127.0.0.1:34254")?; +fn open_stream(browser: String, port: u16) -> io::Result<()> { +    let listener = TcpListener::bind( +        format!("127.0.0.1:{}", port) +    )?;      for stream in listener.incoming() {          match stream { @@ -21,7 +23,7 @@ fn open_stream() -> io::Result<()> {                  Command::new("open")                      .arg("-a") -                    .arg("Opera") +                    .arg(&browser)                      // Trim the trailing newline, otherwise this doesn't                      // work @@ -73,7 +75,7 @@ fn main() {          None => DEFAULT_PORT,      }; -    open_stream().unwrap_or_else(|e| { +    open_stream(browser, port).unwrap_or_else(|e| {          writeln!(io::stderr(), "{}", e)              .expect("Failed printing to stderr");      }); | 
