Skip to main content

sonos_cli/cli/
commands.rs

1use clap::{Subcommand, ValueEnum};
2
3/// CLI subcommands — parsing only, no execution logic.
4#[derive(Debug, Subcommand)]
5pub enum Commands {
6    /// List all speakers
7    Speakers,
8    /// List all groups
9    Groups,
10    /// Show current playback status
11    Status,
12    /// Start playback
13    Play,
14    /// Pause playback
15    Pause,
16    /// Stop playback
17    Stop,
18    /// Skip to next track
19    Next,
20    /// Skip to previous track
21    #[command(name = "prev")]
22    Previous,
23    /// Set volume level (0-100)
24    Volume {
25        /// Volume level (0-100)
26        level: u8,
27    },
28    /// Mute playback
29    Mute,
30    /// Unmute playback
31    Unmute,
32    /// Seek to a position in the current track
33    Seek {
34        /// Target position in H:MM:SS format
35        position: String,
36    },
37    /// Set play mode
38    Mode {
39        /// Play mode
40        #[arg(value_enum)]
41        mode: PlayModeArg,
42    },
43    /// Set bass level (-10 to 10), speaker-only
44    Bass {
45        /// Bass level (-10 to 10)
46        level: i8,
47    },
48    /// Set treble level (-10 to 10), speaker-only
49    Treble {
50        /// Treble level (-10 to 10)
51        level: i8,
52    },
53    /// Set loudness compensation (on/off), speaker-only
54    Loudness {
55        /// on or off
56        #[arg(value_enum)]
57        state: OnOff,
58    },
59    /// Add a speaker to a group
60    Join,
61    /// Remove a speaker from its group
62    Leave,
63    /// Set or cancel a sleep timer
64    Sleep {
65        /// Duration (30m, 1h, 90m) or "cancel"
66        duration: String,
67    },
68    /// Manage the playback queue
69    Queue {
70        #[command(subcommand)]
71        action: Option<QueueAction>,
72    },
73    /// Manage configuration
74    Config {
75        #[command(subcommand)]
76        action: Option<ConfigAction>,
77    },
78}
79
80/// Config sub-subcommands.
81#[derive(Debug, Subcommand)]
82pub enum ConfigAction {
83    /// Manage speaker/group aliases
84    Alias {
85        /// Speaker or group name
86        name: Option<String>,
87        /// Short alias to assign
88        alias: Option<String>,
89    },
90}
91
92/// Queue sub-subcommands.
93#[derive(Debug, Subcommand)]
94pub enum QueueAction {
95    /// Add a URI to the queue
96    Add {
97        /// Sonos URI to add
98        uri: String,
99    },
100    /// Clear the entire queue
101    Clear,
102}
103
104#[derive(Debug, Clone, ValueEnum)]
105pub enum OnOff {
106    On,
107    Off,
108}
109
110#[derive(Debug, Clone, ValueEnum)]
111pub enum PlayModeArg {
112    Normal,
113    Repeat,
114    #[value(name = "repeat-one")]
115    RepeatOne,
116    Shuffle,
117    #[value(name = "shuffle-no-repeat")]
118    ShuffleNoRepeat,
119}
120
121impl PlayModeArg {
122    pub fn to_sdk(&self) -> sonos_sdk::PlayMode {
123        match self {
124            Self::Normal => sonos_sdk::PlayMode::Normal,
125            Self::Repeat => sonos_sdk::PlayMode::RepeatAll,
126            Self::RepeatOne => sonos_sdk::PlayMode::RepeatOne,
127            Self::Shuffle => sonos_sdk::PlayMode::Shuffle,
128            Self::ShuffleNoRepeat => sonos_sdk::PlayMode::ShuffleNoRepeat,
129        }
130    }
131}