Add version string CLI parameter, set name to optional parameter, default to 'librespot'

This commit is contained in:
Sasha Hilton 2021-02-23 18:35:57 +00:00
parent c8e45ab690
commit 4beb3d5e60

View file

@ -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)] #[derive(Clone)]
struct Setup { struct Setup {
backend: fn(Option<String>) -> Box<dyn Sink>, backend: fn(Option<String>) -> Box<dyn Sink>,
@ -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", "Path to a directory where system files (credentials, volume) will be cached. Can be different from cache option value",
"SYTEMCACHE", "SYTEMCACHE",
).optflag("", "disable-audio-cache", "Disable caching of the audio data.") ).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("", "device-type", "Displayed device type", "DEVICE_TYPE")
.optopt( .optopt(
"b", "b",
@ -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("", "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", "verbose", "Enable verbose output")
.optflag("V", "version", "Display librespot version string")
.optopt("u", "username", "Username to sign in with", "USERNAME") .optopt("u", "username", "Username to sign in with", "USERNAME")
.optopt("p", "password", "Password", "PASSWORD") .optopt("p", "password", "Password", "PASSWORD")
.optopt("", "proxy", "HTTP proxy to use when connecting", "PROXY") .optopt("", "proxy", "HTTP proxy to use when connecting", "PROXY")
@ -220,6 +231,11 @@ fn setup(args: &[String]) -> Setup {
} }
}; };
if matches.opt_present("version") {
print_version();
exit(0);
}
let verbose = matches.opt_present("verbose"); let verbose = matches.opt_present("verbose");
setup_logging(verbose); setup_logging(verbose);
@ -306,7 +322,7 @@ fn setup(args: &[String]) -> Setup {
.map(|port| port.parse::<u16>().unwrap()) .map(|port| port.parse::<u16>().unwrap())
.unwrap_or(0); .unwrap_or(0);
let name = matches.opt_str("name").unwrap(); let name = matches.opt_str("name").unwrap_or("Librespot".to_string());
let credentials = { let credentials = {
let cached_credentials = cache.as_ref().and_then(Cache::credentials); let cached_credentials = cache.as_ref().and_then(Cache::credentials);