• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

johnallen3d / mpc-rs / #171

27 Dec 2023 02:50PM UTC coverage: 20.149%. Remained the same
#171

push

johnallen3d
refactor: move to workspace project

- separate shared logic into a library
- `cli` is now a thin wrapper of `lib` and arg parsing

Resolves #79

4 of 23 new or added lines in 4 files covered. (17.39%)

227 existing lines in 2 files now uncovered.

135 of 670 relevant lines covered (20.15%)

1.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cli/src/args.rs
1
use clap::{Parser, Subcommand, ValueEnum};
2
use serde::Serialize;
3

4
/// Music Player Daemon client written in Rust
5
#[derive(Debug, Parser)]
6
pub(crate) struct Cli {
7
    #[command(subcommand)]
8
    pub(crate) command: Option<Commands>,
9
    /// Set output format
10
    #[clap(long, value_enum, default_value_t=OutputFormat::Json)]
11
    pub(crate) format: OutputFormat,
12
    /// Set the ip address the mpd server is listening on
13
    #[clap(long, default_value = "127.0.0.1")]
14
    pub(crate) bind_to_address: Option<String>,
15
    /// Set the port the mpd server is listening on
16
    #[clap(long, default_value = "6600")]
17
    pub(crate) port: Option<String>,
18
}
19

20
#[derive(Debug, Subcommand)]
21
pub(crate) enum Commands {
22
    //
23
    // queue related commands
24
    //
25
    /// Add a song to the queue at the given path (or dir '/')
26
    #[command()]
27
    Add { path: Option<String> },
28
    /// Remove all but the current song from the queue
29
    #[command()]
30
    Crop,
31
    /// Print the current song
32
    #[command()]
33
    Current,
34
    /// Print the current song
35
    #[command()]
36
    Del { position: Option<u32> },
37

38
    //
39
    // playback related commands
40
    //
41
    /// Start the player
42
    #[command()]
43
    Play { position: Option<u32> },
44
    /// Next song in the queue
45
    #[command()]
46
    Next,
47
    /// Previous song in the queue
48
    #[command()]
49
    Prev,
50
    /// Pause the player
51
    #[command()]
52
    Pause,
53
    /// Pause the player if it is playing
54
    #[command()]
55
    PauseIfPlaying,
56
    /// CD player like previous song
57
    #[command()]
58
    Cdprev,
59
    /// Toggle play/pause
60
    #[command()]
61
    Toggle,
62
    /// Stop the player
63
    #[command()]
64
    Stop,
65
    /// Seek the current track to the given position: [+-][HH:MM:SS]|<0-100>%
66
    #[command()]
67
    Seek { position: String },
68
    /// Seek the current track or through the playslist : [+-][HH:MM:SS]
69
    #[command()]
70
    Seekthrough { position: String },
71

72
    //
73
    // playlist related commands
74
    //
75
    /// Clear the current playlist
76
    #[command()]
77
    Clear,
78
    /// List current outputs
79
    #[command()]
80
    Outputs,
81
    /// Enable the given output(s).
82
    /// example: `mp-cli enable [only] <output # or name> [...]`
83
    #[command()]
84
    Enable { args: Vec<String> },
85
    /// Disable the given output(s).
86
    /// example: `mp-cli disable [only] <output # or name> [...]`
87
    #[command()]
88
    Disable { args: Vec<String> },
89
    /// Toggle the given output(s).
90
    /// example: `mp-cli toggleoutput <output # or name> [...]`
91
    #[command()]
92
    Toggleoutput { args: Vec<String> },
93
    /// Display the next song in the queue
94
    #[command()]
95
    Queued,
96
    /// Shuffle the queue
97
    #[command()]
98
    Shuffle,
99
    /// List all of the playlists
100
    #[command()]
101
    Lsplaylists,
102
    /// Load a playlist into the queue (optionally provide a range)
103
    #[command()]
104
    Load { name: String, range: Option<String> },
105
    /// Insert a song into the queue after the current song
106
    #[command()]
107
    Insert { uri: Option<String> },
108
    /// Set priority (0 default through 255) of song(s) in the queue
109
    #[command()]
110
    Prio {
111
        priority: String,
112
        position_or_range: String,
113
    },
114
    /// List songs in a playlist
115
    #[command()]
116
    Playlist { name: Option<String> },
117
    /// List all songs in the music directory
118
    #[command()]
119
    Listall { file: Option<String> },
120
    /// List the contents of a direcotyr (defaults to `music_directory`)
121
    #[command()]
122
    Ls { directory: Option<String> },
123
    /// Toggle repeat mode or set to provided state
124
    #[command()]
125
    Repeat { state: Option<OnOff> },
126
    /// Toggle random mode or set to provided state
127
    #[command()]
128
    Random { state: Option<OnOff> },
129
    /// Toggle single mode or set to provided state
130
    #[command()]
131
    Single { state: Option<OnOff> },
132
    /// Toggle consume mode or set to provided state
133
    #[command()]
134
    Consume { state: Option<OnOff> },
135
    /// Toggle consume mode or set to provided state
136
    #[command()]
137
    Crossfade { seconds: Option<String> },
138

139
    /// Save queue to a playlist
140
    #[command()]
141
    Save { name: String },
142
    /// Remove a playlist
143
    #[command()]
144
    Rm { name: String },
145
    /// Set the volume to specified value <num> or increase/decrease it [+-]<num>
146
    #[command()]
147
    Volume { volume: String },
148

149
    /// Provide mpd statistics
150
    #[command()]
151
    Stats,
152
    /// Provide the mpd version and the mp-cli version
153
    #[command()]
154
    Version,
155

156
    //
157
    // output related commands
158
    //
159
    /// Get the current status of the player
160
    #[command()]
161
    Status,
162
}
163

164
#[derive(Clone, Debug, ValueEnum)]
165
pub enum OutputFormat {
166
    Text,
167
    Json,
168
}
169

170
impl OutputFormat {
NEW
171
    pub fn to(&self) -> mpd_easy::OutputFormat {
×
NEW
172
        match self {
×
NEW
173
            OutputFormat::Text => mpd_easy::OutputFormat::Text,
×
NEW
174
            OutputFormat::Json => mpd_easy::OutputFormat::Json,
×
175
        }
176
    }
177
}
178

179
#[derive(Clone, Debug, PartialEq, Serialize, ValueEnum)]
180
pub enum OnOff {
181
    On,
182
    Off,
183
}
184

185
impl OnOff {
186
    pub fn to(value: &Option<OnOff>) -> Option<mpd_easy::OnOff> {
NEW
187
        match value {
×
NEW
188
            Some(OnOff::On) => Some(mpd_easy::OnOff::On),
×
NEW
189
            Some(OnOff::Off) => Some(mpd_easy::OnOff::Off),
×
NEW
190
            None => None,
×
191
        }
192
    }
193
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc