Skip to content

Commit

Permalink
Replace XDG_DATA_HOME by XDG_CONFIG_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed Sep 25, 2024
1 parent b633eba commit b4e1629
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose --features=integration-tests
run: cargo test --verbose --features=integration-tests --test-threads=1
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## blissify 0.5.2
* Put the `--config-path` argument after the subcommand for consistency's sake.
* Use XDG_CONFIG_HOME instead of XDG_DATA_HOME to put config files, making
sure to still check XDG_DATA_HOME for users with an existing database.
* Integration tests can now be run using `cargo test --features=integration-tests`.

## blissify 0.5.1
Expand Down
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rpi = ["bliss-audio/rpi"]
integration-tests = ["bliss-audio/integration-tests"]

[dependencies]
bliss-audio = "0.9.2"
bliss-audio = {git = "https://github.com/Polochon-street/bliss-rs", branch = "library-change-xdg-thing"}
mpd = "0.1.0"
dirs = "3.0.1"
tempdir = "0.3.7"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ It will create a configuration file `config.json` and a database file
`songs.db` in `~/.local/share/bliss-rs`. If you want to specify a different
path for the configuration file and the database file, running
```
$ blissify -c /path/to/configuration.json init -d /path/to/database.db /path/to/mpd/root
$ blissify init -d /path/to/database.db /path/to/mpd/root -c /path/to/configuration.json
```
should do the trick. All the subsequent blissify commands should start
with `blissify -c /path/to/configuration.json` in order to work.
with `blissify <command> -c /path/to/configuration.json` in order to work.

Note that it may take several minutes (up to some hours, on very large
libraries with more than for instance 20k songs) to complete.
Expand Down
42 changes: 30 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,40 +805,48 @@ fn parse_number_cores(matches: &ArgMatches) -> Result<Option<NonZeroUsize>, Blis

fn main() -> Result<()> {
env_logger::init_from_env(env_logger::Env::default().filter_or("RUST_LOG", "warn"));
let config_argument = Arg::with_name("config-path")
.short("c")
.long("config-path")
.help(
"Optional argument specifying the configuration path, for both loading and initializing blissify. Example: \"/path/to/config.json\". If not specified, defaults to \"XDG_CONFIG_HOME/bliss-rs/config.json\", e.g. \"/home/user/.config/bliss-rs/config.json\".",
)
.required(false)
.takes_value(true);

let matches = App::new("blissify")
.version(env!("CARGO_PKG_VERSION"))
.author("Polochon_street")
.about("Analyze and make smart playlists from an MPD music database.")
.arg(Arg::with_name("config-path")
.short("c")
.long("config-path")
.help(
"Optional argument specifying the configuration path, for both loading and initializing blissify. Example: \"/path/to/config.json\".",
)
.required(false)
.takes_value(true)
)
.arg(config_argument.clone().hidden(true))
.subcommand(
SubCommand::with_name("list-db")
.about("Print songs that have been analyzed and are in blissify's database.")
.arg(Arg::with_name("detailed").long("detailed")
.takes_value(false)
.help("Display analyzed song paths, as well as the corresponding analysis.")
)
.arg(config_argument.clone())
)
.subcommand(
SubCommand::with_name("init")
.about("Initializes an MPD library")
.about(
"Initialize blissify on an MPD library.\n\
By default, it creates the configuration folder \"bliss-rs\" \
in XDG_CONFIG_HOME, most likely `/home/user/.config/bliss-rs`, \
and analyzes the songs in the given MPD library.\n\
It can take some time."
)
.arg(Arg::with_name("MPD_BASE_PATH")
.help("MPD base path. The value of `music_directory` in your mpd.conf.")
.required(true)
)
.arg(config_argument.clone())
.arg(Arg::with_name("database-path")
.short("d")
.long("database-path")
.help(
"Optional argument specifying where to store the database containing analyzed songs. Example: \"/path/to/bliss.db\"",
"Optional argument specifying where to store the database containing analyzed songs. Example: \"/path/to/bliss.db\". If not specified, defaults to \"XDG_CONFIG_HOME/bliss-rs/songs.db\", e.g. \"/home/user/.config/bliss-rs/songs.db\"."
)
.required(false)
.takes_value(true)
Expand All @@ -854,6 +862,7 @@ Useful to avoid a too heavy load on a machine.")
)
.subcommand(
SubCommand::with_name("rescan")
.arg(config_argument.clone())
.arg(Arg::with_name("number-cores")
.long("number-cores")
.help(
Expand All @@ -866,6 +875,7 @@ Useful to avoid a too heavy load on a machine.")
)
.subcommand(
SubCommand::with_name("update")
.arg(config_argument.clone())
.arg(Arg::with_name("number-cores")
.long("number-cores")
.help(
Expand All @@ -879,6 +889,7 @@ Useful to avoid a too heavy load on a machine.")
.subcommand(
SubCommand::with_name("playlist")
.about("Make a playlist from the currently playing song, clearing the queue and queuing NUMBER_SONGS songs similar to the currently playing song. See the other flags if you want to e.g. preserve the queue.")
.arg(config_argument.clone())
.arg(Arg::with_name("NUMBER_SONGS")
.help("Number of items to queue, including the first song.")
.required(true)
Expand Down Expand Up @@ -942,6 +953,7 @@ Useful to avoid a too heavy load on a machine.")
.about(
"Make a playlist, prompting a set of close songs, and asking which one will be the most appropriate."
)
.arg(config_argument.clone())
.arg(Arg::with_name("continue")
.long("continue")
.help(
Expand All @@ -960,7 +972,13 @@ Defaults to 3, cannot be more than 9."
)
.get_matches();

let config_path = matches.value_of("config-path").map(PathBuf::from);
let mut config_path = match matches.subcommand() {
(_, Some(sub_m)) => sub_m.value_of("config-path").map(PathBuf::from),
_ => None,
};
if config_path.is_none() {
config_path = matches.value_of("config-path").map(PathBuf::from);
}
if let Some(sub_m) = matches.subcommand_matches("list-db") {
let library = MPDLibrary::from_config_path(config_path)?;
let mut songs: Vec<LibrarySong<()>> = library.library.songs_from_library()?;
Expand Down
20 changes: 13 additions & 7 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ mod tests {
"#;

struct TestSettings {
mpd_conf_file: assert_fs::NamedTempFile,
_mpd_conf_file: assert_fs::NamedTempFile,
socket_file: assert_fs::NamedTempFile,
handle: Child,
_handle: Child,
}

fn start_mpd() -> Result<TestSettings, Box<dyn std::error::Error>> {
Expand All @@ -47,9 +47,9 @@ mod tests {
.spawn()?;

Ok(TestSettings {
mpd_conf_file,
_mpd_conf_file: mpd_conf_file,
socket_file,
handle,
_handle: handle,
})
}

Expand Down Expand Up @@ -105,12 +105,12 @@ mod tests {
}

let mut cmd = Command::cargo_bin("blissify")?;
cmd.arg("-c")
.arg(temp_dir.path().join("test.json"))
.arg("init")
cmd.arg("init")
.arg(data_directory)
.arg("-d")
.arg(temp_dir.path().join("test.db"))
.arg("-c")
.arg(temp_dir.path().join("test.json"))
.env("MPD_HOST", socket_path);
cmd.assert().success();
assert!(temp_dir.path().join("test.json").exists());
Expand All @@ -122,6 +122,12 @@ mod tests {
fn test_list_db_fail() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("blissify")?;

cmd.arg("list-db").arg("-c").arg("/tmp/nonexisting");
cmd.assert()
.failure()
.stderr(predicate::str::contains("No such file or directory"));

let mut cmd = Command::cargo_bin("blissify")?;
cmd.arg("-c").arg("/tmp/nonexisting").arg("list-db");
cmd.assert()
.failure()
Expand Down

0 comments on commit b4e1629

Please sign in to comment.