Subcommands for controlling MPD

devel
~erin 2023-03-21 23:24:40 -04:00
parent 70b77cfb72
commit 701345de29
Signed by: erin
GPG Key ID: 9A8E308CEFA37A47
2 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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