Replace dependency structopt with clap
This commit is contained in:
parent
391949cde6
commit
ef234f0ec0
5 changed files with 163 additions and 107 deletions
167
Cargo.lock
generated
167
Cargo.lock
generated
|
@ -117,6 +117,54 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "approx"
|
name = "approx"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
@ -189,7 +237,7 @@ dependencies = [
|
||||||
"cexpr",
|
"cexpr",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"clang-sys",
|
"clang-sys",
|
||||||
"clap",
|
"clap 2.34.0",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lazycell",
|
"lazycell",
|
||||||
|
@ -432,12 +480,52 @@ dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"strsim",
|
"strsim 0.8.0",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"vec_map",
|
"vec_map",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "46ca43acc1b21c6cc2d1d3129c19e323a613935b5bc28fb3b33b5b2e5fb00030"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim 0.10.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.22",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "claxon"
|
name = "claxon"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
@ -469,6 +557,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "com-rs"
|
name = "com-rs"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
@ -1125,12 +1219,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.3.3"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
dependencies = [
|
|
||||||
"unicode-segmentation",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
|
@ -1579,10 +1670,10 @@ name = "mpd_info_screen"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
"clap 4.4.9",
|
||||||
"freetype",
|
"freetype",
|
||||||
"ggez",
|
"ggez",
|
||||||
"image",
|
"image",
|
||||||
"structopt",
|
|
||||||
"wgpu",
|
"wgpu",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1991,30 +2082,6 @@ dependencies = [
|
||||||
"toml_edit",
|
"toml_edit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.107",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.63"
|
version = "1.0.63"
|
||||||
|
@ -2399,28 +2466,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "structopt"
|
name = "strsim"
|
||||||
version = "0.3.26"
|
version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"lazy_static",
|
|
||||||
"structopt-derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "structopt-derive"
|
|
||||||
version = "0.4.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.107",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "symphonia"
|
name = "symphonia"
|
||||||
|
@ -2670,12 +2719,6 @@ version = "1.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-segmentation"
|
|
||||||
version = "1.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
|
@ -2688,6 +2731,12 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.2.2"
|
version = "1.2.2"
|
||||||
|
|
|
@ -10,7 +10,7 @@ resolver = "2"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
structopt = "0.3"
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
image = "0.24"
|
image = "0.24"
|
||||||
ggez = "0.9.3"
|
ggez = "0.9.3"
|
||||||
freetype = { version = "0.7", optional = true }
|
freetype = { version = "0.7", optional = true }
|
||||||
|
|
49
README.md
49
README.md
|
@ -35,28 +35,39 @@ or through crates.io:
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
|
||||||
USAGE:
|
Displays info on currently playing music from an MPD daemon
|
||||||
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
|
||||||
|
|
||||||
FLAGS:
|
Usage: mpd_info_screen [OPTIONS] <HOST> [PORT]
|
||||||
--disable-show-album disable album display
|
|
||||||
--disable-show-artist disable artist display
|
|
||||||
--disable-show-filename disable filename display
|
|
||||||
--disable-show-title disable title display
|
|
||||||
--no-scale-fill don't scale-fill the album art to the window
|
|
||||||
--pprompt input password via prompt
|
|
||||||
-h, --help Prints help information
|
|
||||||
-V, --version Prints version information
|
|
||||||
|
|
||||||
OPTIONS:
|
Arguments:
|
||||||
-l, --log-level <log-level> [default: Error] [possible values: Error, Warning, Debug, Verbose]
|
<HOST>
|
||||||
-p <password>
|
[PORT] [default: 6600]
|
||||||
--pfile <password-file> read password from file
|
|
||||||
-t, --text-bg-opacity <text-bg-opacity> sets the opacity of the text background (0-255) [default: 190]
|
|
||||||
|
|
||||||
ARGS:
|
Options:
|
||||||
<host>
|
-p <PASSWORD>
|
||||||
<port> [default: 6600]
|
|
||||||
|
--disable-show-title
|
||||||
|
disable title display
|
||||||
|
--disable-show-artist
|
||||||
|
disable artist display
|
||||||
|
--disable-show-album
|
||||||
|
disable album display
|
||||||
|
--disable-show-filename
|
||||||
|
disable filename display
|
||||||
|
--pprompt
|
||||||
|
input password via prompt
|
||||||
|
--pfile <PASSWORD_FILE>
|
||||||
|
read password from file
|
||||||
|
--no-scale-fill
|
||||||
|
don't scale-fill the album art to the window
|
||||||
|
-l, --log-level <LOG_LEVEL>
|
||||||
|
[default: error] [possible values: error, warning, debug, verbose]
|
||||||
|
-t, --text-bg-opacity <TEXT_BG_OPACITY>
|
||||||
|
sets the opacity of the text background (0-255) [default: 190]
|
||||||
|
-h, --help
|
||||||
|
Print help
|
||||||
|
-V, --version
|
||||||
|
Print version
|
||||||
|
|
||||||
|
|
||||||
Note that presing the Escape key when the window is focused closes the program.
|
Note that presing the Escape key when the window is focused closes the program.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use structopt::clap::arg_enum;
|
use clap::ValueEnum;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum LogState {
|
pub enum LogState {
|
||||||
|
@ -9,14 +9,12 @@ pub enum LogState {
|
||||||
Verbose,
|
Verbose,
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_enum! {
|
#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
pub enum LogLevel {
|
||||||
pub enum LogLevel {
|
Error,
|
||||||
Error,
|
Warning,
|
||||||
Warning,
|
Debug,
|
||||||
Debug,
|
Verbose,
|
||||||
Verbose,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log<T>(msg: T, state: LogState, level: LogLevel)
|
pub fn log<T>(msg: T, state: LogState, level: LogLevel)
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -15,44 +15,42 @@ use std::net::Ipv4Addr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use structopt::StructOpt;
|
use clap::Parser;
|
||||||
|
|
||||||
use debug_log::log;
|
use debug_log::log;
|
||||||
|
|
||||||
#[derive(StructOpt, Debug, Clone)]
|
#[derive(Parser, Debug, Clone)]
|
||||||
#[structopt(name = "mpd_info_screen")]
|
#[command(author, version, about, long_about = None)]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
host: Ipv4Addr,
|
host: Ipv4Addr,
|
||||||
#[structopt(default_value = "6600")]
|
#[arg(default_value = "6600")]
|
||||||
port: u16,
|
port: u16,
|
||||||
#[structopt(short = "p")]
|
#[arg(short = 'p')]
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
#[structopt(long = "disable-show-title", help = "disable title display")]
|
#[arg(long = "disable-show-title", help = "disable title display")]
|
||||||
disable_show_title: bool,
|
disable_show_title: bool,
|
||||||
#[structopt(long = "disable-show-artist", help = "disable artist display")]
|
#[arg(long = "disable-show-artist", help = "disable artist display")]
|
||||||
disable_show_artist: bool,
|
disable_show_artist: bool,
|
||||||
#[structopt(long = "disable-show-album", help = "disable album display")]
|
#[arg(long = "disable-show-album", help = "disable album display")]
|
||||||
disable_show_album: bool,
|
disable_show_album: bool,
|
||||||
#[structopt(long = "disable-show-filename", help = "disable filename display")]
|
#[arg(long = "disable-show-filename", help = "disable filename display")]
|
||||||
disable_show_filename: bool,
|
disable_show_filename: bool,
|
||||||
#[structopt(long = "pprompt", help = "input password via prompt")]
|
#[arg(long = "pprompt", help = "input password via prompt")]
|
||||||
enable_prompt_password: bool,
|
enable_prompt_password: bool,
|
||||||
#[structopt(long = "pfile", help = "read password from file")]
|
#[arg(long = "pfile", help = "read password from file")]
|
||||||
password_file: Option<PathBuf>,
|
password_file: Option<PathBuf>,
|
||||||
#[structopt(
|
#[arg(
|
||||||
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"
|
||||||
)]
|
)]
|
||||||
do_not_fill_scale_album_art: bool,
|
do_not_fill_scale_album_art: bool,
|
||||||
#[structopt(
|
#[arg(
|
||||||
short = "l",
|
short = 'l',
|
||||||
long = "log-level",
|
long = "log-level",
|
||||||
possible_values = &debug_log::LogLevel::variants(),
|
default_value = "error",
|
||||||
default_value = "Error",
|
|
||||||
case_insensitive = true,
|
|
||||||
)]
|
)]
|
||||||
log_level: debug_log::LogLevel,
|
log_level: debug_log::LogLevel,
|
||||||
#[structopt(
|
#[arg(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
help = "sets the opacity of the text background (0-255)",
|
help = "sets the opacity of the text background (0-255)",
|
||||||
|
@ -62,7 +60,7 @@ pub struct Opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), String> {
|
fn main() -> Result<(), String> {
|
||||||
let mut opt = Opt::from_args();
|
let mut opt = Opt::parse();
|
||||||
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.
|
// Read password from file if exists, error otherwise.
|
||||||
|
|
Loading…
Reference in a new issue