test/DumpDatabase: use libfmt

This commit is contained in:
Max Kellermann 2024-01-04 15:29:36 +01:00
parent c8e2ab6781
commit 4ed8313954
1 changed files with 12 additions and 15 deletions

View File

@ -18,11 +18,9 @@
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/PrintException.hxx" #include "util/PrintException.hxx"
#include <fmt/core.h>
#include <stdexcept> #include <stdexcept>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <stdlib.h> #include <stdlib.h>
@ -53,42 +51,41 @@ InputStream::LockRead(void *, size_t)
class MyDatabaseListener final : public DatabaseListener { class MyDatabaseListener final : public DatabaseListener {
public: public:
void OnDatabaseModified() noexcept override { void OnDatabaseModified() noexcept override {
cout << "DatabaseModified" << endl; fmt::print("DatabaseModified\n");
} }
void OnDatabaseSongRemoved(const char *uri) noexcept override { void OnDatabaseSongRemoved(const char *uri) noexcept override {
cout << "SongRemoved " << uri << endl; fmt::print("SongRemoved '{}'\n", uri);
} }
}; };
static void static void
DumpDirectory(const LightDirectory &directory) DumpDirectory(const LightDirectory &directory)
{ {
cout << "D " << directory.GetPath() << endl; fmt::print("D {}\n", directory.GetPath());
} }
static void static void
DumpSong(const LightSong &song) DumpSong(const LightSong &song)
{ {
cout << "S ";
if (song.directory != nullptr) if (song.directory != nullptr)
cout << song.directory << "/"; fmt::print("S {}/{}\n", song.directory, song.uri);
cout << song.uri << endl; else
fmt::print("S {}\n", song.uri);
} }
static void static void
DumpPlaylist(const PlaylistInfo &playlist, const LightDirectory &directory) DumpPlaylist(const PlaylistInfo &playlist, const LightDirectory &directory)
{ {
cout << "P " << directory.GetPath() fmt::print("P {}/{}\n", directory.GetPath(), playlist.name);
<< "/" << playlist.name.c_str() << endl;
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
try { try {
if (argc != 3) { if (argc != 3) {
cerr << "Usage: DumpDatabase CONFIG PLUGIN" << endl; fmt::print(stderr, "Usage: DumpDatabase CONFIG PLUGIN\n");
return 1; return EXIT_FAILURE;
} }
const FromNarrowPath config_path = argv[1]; const FromNarrowPath config_path = argv[1];
@ -96,7 +93,7 @@ try {
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name); const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
if (plugin == nullptr) { if (plugin == nullptr) {
cerr << "No such database plugin: " << plugin_name << endl; fmt::print(stderr, "No such database plugin: {}\n", plugin_name);
return EXIT_FAILURE; return EXIT_FAILURE;
} }