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

johnallen3d / mpc-rs / #177

27 Dec 2023 03:38PM UTC coverage: 19.014% (-1.1%) from 20.149%
#177

push

web-flow
feat: add `search` command (#83)

Relates to #16

0 of 40 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

135 of 710 relevant lines covered (19.01%)

1.15 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
    /// Add a song to the queue at the given path (or dir '/')
23
    #[command()]
24
    Add { path: Option<String> },
25
    /// Remove all but the current song from the queue
26
    #[command()]
27
    Crop,
28
    /// Print the current song
29
    #[command()]
30
    Current,
31
    /// Print the current song
32
    #[command()]
33
    Del { position: Option<u32> },
34
    /// Start the player
35
    #[command()]
36
    Play { position: Option<u32> },
37
    /// Next song in the queue
38
    #[command()]
39
    Next,
40
    /// Previous song in the queue
41
    #[command()]
42
    Prev,
43
    /// Pause the player
44
    #[command()]
45
    Pause,
46
    /// Pause the player if it is playing
47
    #[command()]
48
    PauseIfPlaying,
49
    /// CD player like previous song
50
    #[command()]
51
    Cdprev,
52
    /// Toggle play/pause
53
    #[command()]
54
    Toggle,
55
    /// Stop the player
56
    #[command()]
57
    Stop,
58
    /// Seek the current track to the given position: [+-][HH:MM:SS]|<0-100>%
59
    #[command()]
60
    Seek { position: String },
61
    /// Seek the current track or through the playslist : [+-][HH:MM:SS]
62
    #[command()]
63
    Seekthrough { position: String },
64
    /// Clear the current playlist
65
    #[command()]
66
    Clear,
67
    /// List current outputs
68
    #[command()]
69
    Outputs,
70
    /// Enable the given output(s).
71
    /// example: `mp-cli enable [only] <output # or name> [...]`
72
    #[command()]
73
    Enable { args: Vec<String> },
74
    /// Disable the given output(s).
75
    /// example: `mp-cli disable [only] <output # or name> [...]`
76
    #[command()]
77
    Disable { args: Vec<String> },
78
    /// Toggle the given output(s).
79
    /// example: `mp-cli toggleoutput <output # or name> [...]`
80
    #[command()]
81
    Toggleoutput { args: Vec<String> },
82
    /// Display the next song in the queue
83
    #[command()]
84
    Queued,
85
    /// Shuffle the queue
86
    #[command()]
87
    Shuffle,
88
    /// List all of the playlists
89
    #[command()]
90
    Lsplaylists,
91
    /// Load a playlist into the queue (optionally provide a range)
92
    #[command()]
93
    Load { name: String, range: Option<String> },
94
    /// Insert a song into the queue after the current song
95
    #[command()]
96
    Insert { uri: Option<String> },
97
    /// Set priority (0 default through 255) of song(s) in the queue
98
    #[command()]
99
    Prio {
100
        priority: String,
101
        position_or_range: String,
102
    },
103
    /// List songs in a playlist
104
    #[command()]
105
    Playlist { name: Option<String> },
106
    /// List all songs in the music directory
107
    #[command()]
108
    Listall { file: Option<String> },
109
    /// List the contents of a direcotyr (defaults to `music_directory`)
110
    #[command()]
111
    Ls { directory: Option<String> },
112
    /// Toggle repeat mode or set to provided state
113
    #[command()]
114
    Repeat { state: Option<OnOff> },
115
    /// Toggle random mode or set to provided state
116
    #[command()]
117
    Random { state: Option<OnOff> },
118
    /// Toggle single mode or set to provided state
119
    #[command()]
120
    Single { state: Option<OnOff> },
121
    /// Toggle consume mode or set to provided state
122
    #[command()]
123
    Consume { state: Option<OnOff> },
124
    /// Search for songs by type and query
125
    #[command()]
126
    Search { tag: Tag, query: String },
127
    /// Toggle consume mode or set to provided state
128
    #[command()]
129
    Crossfade { seconds: Option<String> },
130
    /// Save queue to a playlist
131
    #[command()]
132
    Save { name: String },
133
    /// Remove a playlist
134
    #[command()]
135
    Rm { name: String },
136
    /// Set the volume to specified value <num> or increase/decrease it [+-]<num>
137
    #[command()]
138
    Volume { volume: String },
139
    /// Provide mpd statistics
140
    #[command()]
141
    Stats,
142
    /// Provide the mpd version and the mp-cli version
143
    #[command()]
144
    Version,
145
    /// Get the current status of the player
146
    #[command()]
147
    Status,
148
}
149

150
#[derive(Clone, Debug, ValueEnum)]
151
pub enum OutputFormat {
152
    Text,
153
    Json,
154
}
155

156
impl OutputFormat {
157
    pub fn to(&self) -> mpd_easy::OutputFormat {
×
158
        match self {
×
159
            OutputFormat::Text => mpd_easy::OutputFormat::Text,
×
160
            OutputFormat::Json => mpd_easy::OutputFormat::Json,
×
161
        }
162
    }
163
}
164

165
#[derive(Clone, Debug, PartialEq, Serialize, ValueEnum)]
166
pub enum OnOff {
167
    On,
168
    Off,
169
}
170

171
impl OnOff {
172
    pub fn to(value: &Option<OnOff>) -> Option<mpd_easy::OnOff> {
173
        match value {
×
174
            Some(OnOff::On) => Some(mpd_easy::OnOff::On),
×
175
            Some(OnOff::Off) => Some(mpd_easy::OnOff::Off),
×
176
            None => None,
×
177
        }
178
    }
179
}
180

181
#[derive(Clone, Debug, ValueEnum)]
182
pub enum Tag {
183
    Artist,
184
    ArtistSort,
185
    Album,
186
    AlbumSort,
187
    AlbumArtist,
188
    AlbumSortOrder,
189
    Title,
190
    Track,
191
    Name,
192
    Genre,
193
    Date,
194
    Composer,
195
    Performer,
196
    Conductor,
197
    Work,
198
    Grouping,
199
    Comment,
200
    Disc,
201
    Label,
202
    MusicbrainzArtistId,
203
    MusicbrainzAlbumId,
204
    MusicbrainzAlbumArtistId,
205
    MusicbrainzTrackId,
206
    MusicbrainzReleaseTrackId,
207
    MusicbrainzWorkId,
208
    Any,
209
}
210

211
impl Tag {
NEW
212
    pub fn to_str(&self) -> &str {
×
NEW
213
        match self {
×
NEW
214
            Tag::Artist => "Artist",
×
NEW
215
            Tag::ArtistSort => "ArtistSort",
×
NEW
216
            Tag::Album => "Album",
×
NEW
217
            Tag::AlbumSort => "AlbumSort",
×
NEW
218
            Tag::AlbumArtist => "AlbumArtist",
×
NEW
219
            Tag::AlbumSortOrder => "AlbumSortOrder",
×
NEW
220
            Tag::Title => "Title",
×
NEW
221
            Tag::Track => "Track",
×
NEW
222
            Tag::Name => "Name",
×
NEW
223
            Tag::Genre => "Genre",
×
NEW
224
            Tag::Date => "Date",
×
NEW
225
            Tag::Composer => "Composer",
×
NEW
226
            Tag::Performer => "Performer",
×
NEW
227
            Tag::Conductor => "Conductor",
×
NEW
228
            Tag::Work => "Work",
×
NEW
229
            Tag::Grouping => "Grouping",
×
NEW
230
            Tag::Comment => "Comment",
×
NEW
231
            Tag::Disc => "Disc",
×
NEW
232
            Tag::Label => "Label",
×
NEW
233
            Tag::MusicbrainzArtistId => "MusicbrainzArtistId",
×
NEW
234
            Tag::MusicbrainzAlbumId => "MusicbrainzAlbumId",
×
NEW
235
            Tag::MusicbrainzAlbumArtistId => "MusicbrainzAlbumArtistId",
×
NEW
236
            Tag::MusicbrainzTrackId => "MusicbrainzTrackId",
×
NEW
237
            Tag::MusicbrainzReleaseTrackId => "MusicbrainzReleaseTrackId",
×
NEW
238
            Tag::MusicbrainzWorkId => "MusicbrainzWorkId",
×
NEW
239
            Tag::Any => "Any",
×
240
        }
241
    }
242
}
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

© 2025 Coveralls, Inc