-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,63 @@ | ||
use clap::{Args, Parser, Subcommand}; | ||
use mprisence::Mprisence; | ||
use tokio; | ||
|
||
#[derive(Debug, Parser)] | ||
#[command(name = "mprisence")] | ||
#[command(long_about = None)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
command: Option<Commands>, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Commands { | ||
#[command(name = "start", about = "Start the mprisence daemon")] | ||
Start, | ||
#[command(name = "player", about = "Commands for interacting with players")] | ||
Player(PlayerArgs), | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
struct PlayerArgs { | ||
#[command(subcommand)] | ||
command: PlayerCommands, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum PlayerCommands { | ||
#[command(name = "list", about = "List all available players")] | ||
List, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init(); | ||
log::info!("Starting mprisence"); | ||
Mprisence::new().start().await; | ||
let cli = Cli::parse(); | ||
|
||
match cli.command { | ||
Some(Commands::Start) | None => { | ||
env_logger::init(); | ||
log::info!("Starting mprisence"); | ||
Mprisence::new().start().await; | ||
} | ||
Some(Commands::Player(player)) => match player.command { | ||
PlayerCommands::List => { | ||
let players = mprisence::player::get_players(); | ||
|
||
println!("Found {} players", players.len()); | ||
|
||
for player in players { | ||
print!("- {}", player.identity()); | ||
|
||
if let Ok(metadata) = player.get_metadata() { | ||
if let Some(title) = metadata.url() { | ||
print!(" : {}", title); | ||
} | ||
} | ||
|
||
println!(); | ||
} | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters