From c1651ed993bb383937ed845279e161bc572a254f Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sat, 7 Jun 2025 11:43:42 +0200 Subject: [PATCH] Subcommand --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 2 +- src/main.rs | 37 ++++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1aff74e..57729d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,14 +110,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hello-world" -version = "0.1.0" -dependencies = [ - "clap", - "mpd", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -133,6 +125,14 @@ dependencies = [ "bufstream", ] +[[package]] +name = "noise" +version = "0.1.0" +dependencies = [ + "clap", + "mpd", +] + [[package]] name = "once_cell_polyfill" version = "1.70.1" diff --git a/Cargo.toml b/Cargo.toml index 63cf231..2be2315 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hello-world" +name = "noise" version = "0.1.0" edition = "2024" diff --git a/src/main.rs b/src/main.rs index 2a2478f..90b242d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,27 +1,34 @@ extern crate mpd; use mpd::Client; -use std::net::TcpStream; +// use std::net::TcpStream; -use clap::Parser; +use clap::{Parser, Subcommand}; -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] -struct Args { - #[arg(short, long)] - name: String, - #[arg(short, long)] - count: u8, +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +#[command(propagate_version = true)] + +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + /// Adds files to myapp + Add { name: Option }, } fn main() { let mut conn = Client::connect("localhost:6600").unwrap(); - conn.volume(100).unwrap(); - println!("Status: {:?}", conn.status()); + conn.toggle_pause().unwrap(); - // let args = Args::parse(); - // for _ in 0..args.count { - // println!("Hello {}!", args.name) - // } + let cli = Cli::parse(); + match &cli.command { + Commands::Add { name } => { + println!("'myapp add' was used, name is: {:?}", name) + } + } }