Subcommands for controlling MPD
parent
70b77cfb72
commit
701345de29
|
@ -18,8 +18,6 @@ A simple `TUI` and commandline client for `mpd`.
|
|||
|
||||
`-V/--version` - Print version information
|
||||
|
||||
`-j/--json` - Output in JSON format
|
||||
|
||||
### Subcommands
|
||||
`stop` - Stop playing
|
||||
|
||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -19,7 +19,7 @@ use tui::{
|
|||
};
|
||||
|
||||
use paris::error;
|
||||
use clap::Parser;
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
|
||||
mod structs;
|
||||
use structs::{App, StatefulList, InputMode};
|
||||
|
@ -38,12 +38,42 @@ struct Args {
|
|||
/// Specify a configuration file
|
||||
#[arg(short, long)]
|
||||
config: Option<String>,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Commands {
|
||||
/// Stop playing
|
||||
Stop,
|
||||
/// Start/resume playing
|
||||
Play,
|
||||
/// Pause playing
|
||||
Pause,
|
||||
}
|
||||
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Parse arguments
|
||||
let args = Args::parse();
|
||||
|
||||
let mut app = App::new(args.port, args.host);
|
||||
match args.command {
|
||||
Some(Commands::Stop) => {
|
||||
app.mpd_client.stop().unwrap();
|
||||
exit(0);
|
||||
},
|
||||
Some(Commands::Play) => {
|
||||
app.mpd_client.play().unwrap();
|
||||
exit(0);
|
||||
},
|
||||
Some(Commands::Pause) => {
|
||||
app.mpd_client.pause(true).unwrap();
|
||||
exit(0);
|
||||
}
|
||||
None => {},
|
||||
}
|
||||
// setup terminal
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = io::stdout();
|
||||
|
@ -53,7 +83,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
// create app and run it
|
||||
let tick_rate = Duration::from_millis(50);
|
||||
let app = App::new(args.port, args.host);
|
||||
|
||||
let res = run_app(&mut terminal, app, tick_rate);
|
||||
|
||||
// restore terminal
|
||||
|
|
Loading…
Reference in New Issue