Skip to content

Commit

Permalink
Add version string CLI parameter, set name to optional parameter, def…
Browse files Browse the repository at this point in the history
…ault to 'librespot'
  • Loading branch information
sashahilton00 committed Feb 23, 2021
1 parent c8e45ab commit 4beb3d5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ fn list_backends() {
}
}

fn print_version() {
println!(
"librespot {semver} {sha} (Built on {build_date}, Build ID: {build_id})",
semver = version::SEMVER,
sha = version::SHA_SHORT,
build_date = version::BUILD_DATE,
build_id = version::BUILD_ID
);
}

#[derive(Clone)]
struct Setup {
backend: fn(Option<String>) -> Box<dyn Sink>,
Expand Down Expand Up @@ -103,7 +113,7 @@ fn setup(args: &[String]) -> Setup {
"Path to a directory where system files (credentials, volume) will be cached. Can be different from cache option value",
"SYTEMCACHE",
).optflag("", "disable-audio-cache", "Disable caching of the audio data.")
.reqopt("n", "name", "Device name", "NAME")
.optopt("n", "name", "Device name", "NAME")
.optopt("", "device-type", "Displayed device type", "DEVICE_TYPE")
.optopt(
"b",
Expand All @@ -119,6 +129,7 @@ fn setup(args: &[String]) -> Setup {
)
.optflag("", "emit-sink-events", "Run program set by --onevent before sink is opened and after it is closed.")
.optflag("v", "verbose", "Enable verbose output")
.optflag("V", "version", "Display librespot version string")
.optopt("u", "username", "Username to sign in with", "USERNAME")
.optopt("p", "password", "Password", "PASSWORD")
.optopt("", "proxy", "HTTP proxy to use when connecting", "PROXY")
Expand Down Expand Up @@ -220,6 +231,11 @@ fn setup(args: &[String]) -> Setup {
}
};

if matches.opt_present("version") {
print_version();
exit(0);
}

let verbose = matches.opt_present("verbose");
setup_logging(verbose);

Expand Down Expand Up @@ -306,7 +322,7 @@ fn setup(args: &[String]) -> Setup {
.map(|port| port.parse::<u16>().unwrap())
.unwrap_or(0);

let name = matches.opt_str("name").unwrap();
let name = matches.opt_str("name").unwrap_or("Librespot".to_string());

let credentials = {
let cached_credentials = cache.as_ref().and_then(Cache::credentials);
Expand Down

0 comments on commit 4beb3d5

Please sign in to comment.