Skip to content

Commit

Permalink
Add player list command
Browse files Browse the repository at this point in the history
  • Loading branch information
lazykern committed Aug 29, 2024
1 parent b53eab9 commit a2fa0fc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
dirs = "5.0.1"
discord-rich-presence = "0.2.3"
env_logger = "0.11.2"
Expand Down
60 changes: 57 additions & 3 deletions src/main.rs
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!();
}
}
},
}
}
4 changes: 2 additions & 2 deletions src/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pub fn get_players() -> Vec<Player> {
}
}
}
},
}
Err(e) => {
log::error!("Error finding players: {:?}", e);
}
}
}

players
}

0 comments on commit a2fa0fc

Please sign in to comment.