diff --git a/Cargo.lock b/Cargo.lock index 44c050a..2d4e9cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -88,22 +88,22 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -207,11 +207,11 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.4.0" +version = "3.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +checksum = "5fd03604047cee9b6ce9de9f70c6cd540a0520c813cbd49bae61f33ab80ed1dc" dependencies = [ - "event-listener 5.4.0", + "event-listener 5.4.1", "event-listener-strategy", "pin-project-lite", ] @@ -238,7 +238,7 @@ dependencies = [ "async-task", "blocking", "cfg-if", - "event-listener 5.4.0", + "event-listener 5.4.1", "futures-lite", "rustix", ] @@ -442,9 +442,9 @@ checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" [[package]] name = "bytemuck" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" +checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" [[package]] name = "bytes" @@ -454,9 +454,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.2.30" +version = "1.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" dependencies = [ "shlex", ] @@ -484,9 +484,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.42" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -504,9 +504,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.42" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -516,9 +516,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", @@ -798,9 +798,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "5.4.0" +version = "5.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" dependencies = [ "concurrent-queue", "parking", @@ -813,7 +813,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" dependencies = [ - "event-listener 5.4.0", + "event-listener 5.4.1", "pin-project-lite", ] @@ -921,9 +921,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" dependencies = [ "fastrand", "futures-core", @@ -1015,9 +1015,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785" +checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" dependencies = [ "atomic-waker", "bytes", @@ -1034,9 +1034,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", "equivalent", @@ -1431,9 +1431,9 @@ dependencies = [ [[package]] name = "indenter" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" [[package]] name = "indexmap" @@ -1575,9 +1575,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libredox" @@ -1945,9 +1945,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "polling" -version = "3.9.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee9b2fa7a4517d2c91ff5bc6c297a427a96749d15f98fcdbb22c05571a4d4b7" +checksum = "b5bd19146350fe804f7cb2669c851c03d69da628803dab0d98018142aaa5d829" dependencies = [ "cfg-if", "concurrent-queue", @@ -2022,9 +2022,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" dependencies = [ "unicode-ident", ] @@ -2085,7 +2085,7 @@ dependencies = [ "serde", "serde_json", "syn 2.0.104", - "thiserror 2.0.12", + "thiserror 2.0.14", "typify", "unicode-ident", ] @@ -2162,7 +2162,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.12", + "thiserror 2.0.14", ] [[package]] @@ -2206,9 +2206,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.22" +version = "0.12.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" +checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" dependencies = [ "base64 0.22.1", "bytes", @@ -2315,9 +2315,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" @@ -2529,9 +2529,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" dependencies = [ "libc", ] @@ -2550,9 +2550,9 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" [[package]] name = "smallvec" @@ -2750,11 +2750,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e" dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl 2.0.14", ] [[package]] @@ -2770,9 +2770,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227" dependencies = [ "proc-macro2", "quote", @@ -2840,9 +2840,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.47.0" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", @@ -2891,9 +2891,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" dependencies = [ "bytes", "futures-core", @@ -3061,7 +3061,7 @@ dependencies = [ "serde", "serde_json", "syn 2.0.104", - "thiserror 2.0.12", + "thiserror 2.0.14", "unicode-ident", ] @@ -3162,9 +3162,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "getrandom 0.3.3", "js-sys", @@ -3705,9 +3705,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.2" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" dependencies = [ "yoke", "zerofrom", diff --git a/README.md b/README.md index 17336e0..cbdeb1d 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,83 @@ -# Immich CLI utilities +# Immich Tools -`immich-tools` is a small command-line utility interacting with an Immich server. It offers the following features: +[![Crates.io](https://img.shields.io/crates/v/immich-tools.svg)](https://crates.io/crates/immich-tools) +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) - - List named faces that do not have an associated date of birth - - Synchronise date of births from a vcard file - - List and delete assets, including filtering offline assets only - - Show details about the server +`immich-tools` is a command-line utility for interacting with [Immich](https://immich.app), a self-hosted photo and +video backup solution. This tool provides various utilities to manage your Immich server from the command line. -Some other features are planned, mainly around using external libraries. Feature ideas and contributions welcome. +## Features + +### Albums +- **List** all albums on your Immich server +- **Delete** albums (all or empty ones only) +- **Auto-create** albums from external libraries folder structure +- **List assets of an album** by album name + +### Assets +- **List** assets (all or offline only) +- **Delete** assets (all or offline only) + +### External libraries +- **List** all libraries +- **Scan** all libraries to detect new assets + +### People +- **List** named faces that do not have an associated date of birth +- **Synchronize** dates of birth from a vCard file + +### Server +- **Show** server version +- **Check** which server features are enabled + +## Installation + +### From Crates.io + +```bash +cargo install immich-tools +``` + +### From Source + +```bash +git clone https://git.enoent.fr/kernald/immich-tools.git +cd immich-tools +cargo build --release +``` + +The binary will be available at `./target/release/immich-tools`. ## Configuration -Different options need to be passed to this tool, mainly: +To connect to your Immich server, you need to provide: - - `server_url`: the API endpoint of the Immich instance to work on - - `api_key`: the API key to use +- `server_url`: The API endpoint of your Immich instance (usually ends with `/api`) +- `api_key`: Your Immich API key (can be generated in the Immich web interface) -These can be passed through different mechanisms: +These can be provided in several ways (in order of precedence): - - Command line arguments, e.g. `immich-tools --server-url https://photos.example.com/api --api-key api-key-goes-here server version` - - Environment variables prefixed with `IMMICH_TOOLS_`, e.g. `IMMICH_TOOLS_SERVER_URL=https://photos.example.com/api IMMICH_TOOLS_API_KEY=api-key-goes-here immich-tools server version` - - Environment variables pointing to files, suffixed with `_FILE`, e.g. `IMMICHTOOLS_SERVER_URL_FILE=~/immich-url.txt IMMICH_TOOLS_API_KEY_FILE=~/immich-api-key.txt immich-tools server version`. This is mostly useful for secrets. - - Through a configuration file, in a well-known, OS-dependent location (on Linux, `~/.config/immichtools/config.toml`, on macOS, `~/Library/Application Support/fr.enoent.Immich-Tools/config.toml`, and on Windows `~\AppData\Roaming\enoent\Immich Tools\config\config.toml`). Note that keys in this file can also be suffixed with `_file` and point to a file containing the value, instead of the value directly. +1. **Command line arguments**: + ```bash + immich-tools --server-url https://photos.example.com/api --api-key your-api-key server version + ``` -Command line arguments take precedence over environment variables, which in turn take precedence over the configuration file. +2. **Environment variables** (prefixed with `IMMICH_TOOLS_`): + ```bash + IMMICH_TOOLS_SERVER_URL=https://photos.example.com/api IMMICH_TOOLS_API_KEY=your-api-key immich-tools server version + ``` -### Example configuration file +3. **Environment variables pointing to files** (suffixed with `_FILE`): + ```bash + IMMICH_TOOLS_SERVER_URL_FILE=~/immich-url.txt IMMICH_TOOLS_API_KEY_FILE=~/immich-api-key.txt immich-tools server version + ``` + +4. **Configuration file** in the OS-specific location: + - Linux: `~/.config/immichtools/config.toml` + - macOS: `~/Library/Application Support/fr.enoent.Immich-Tools/config.toml` + - Windows: `~\AppData\Roaming\enoent\Immich Tools\config\config.toml` + +### Example Configuration File ```toml server_url = "https://photos.example.com/api" @@ -35,6 +87,91 @@ api_key_file = "/home/example/.config/immichtools/apikey" vcard = "/home/example/contacts.vcf" ``` -## Immich API bindings +## Usage Examples -The bindings are generated automatically from `src/immich-openapi-specs.json`. The file currently in the repo has been generated with Immich v1.119.1, with a few methods removed around file upload (Progenitor doesn't yet support `multipart/form-data` content types, see [here](https://github.com/oxidecomputer/progenitor/issues/518)). All other methods should be available. +### Albums + +List all albums: +```bash +immich-tools albums list +``` + +Delete empty albums: +```bash +immich-tools albums delete --empty +``` + +Auto-create albums from folder structure: +```bash +immich-tools albums auto-create --album-name-separator "/" +``` + +List assets belonging to a specific album (by album name): +```bash +immich-tools albums list-assets --album "My Album" +``` + +### Assets + +List all assets: +```bash +immich-tools assets list +``` + +List offline assets only: +```bash +immich-tools assets list --offline +``` + +Delete offline assets: +```bash +immich-tools assets delete --offline +``` + +### External libraries + +List all libraries: +```bash +immich-tools libraries list +``` + +Scan all libraries for new assets: +```bash +immich-tools libraries scan +``` + +### People + +List people missing date of birth: +```bash +immich-tools people missing-date-of-births +``` + +Sync dates of birth from vCard file: +```bash +immich-tools people sync-date-of-births --vcard /path/to/contacts.vcf +``` + +### Server + +Show server version: +```bash +immich-tools server version +``` + +Check enabled server features: +```bash +immich-tools server features +``` + +## Global Options + +- `--dry-run`: Show what would be done without making any changes +- `--no-confirm`: Skip confirmation prompts +- `-v, --verbose`: Increase logging verbosity (can be used multiple times) + +## Immich API Compatibility + +The bindings are generated automatically from the Immich OpenAPI specification. The current version is compatible with +Immich v1.119.1, with some limitations around file upload operations (Progenitor doesn't yet support +`multipart/form-data` content types, see [this issue](https://github.com/oxidecomputer/progenitor/issues/518)). diff --git a/flake.lock b/flake.lock index 73bfdd0..3e8d682 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", "owner": "edolstra", "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", "type": "github" }, "original": { @@ -57,11 +57,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1753694789, - "narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=", + "lastModified": 1754725699, + "narHash": "sha256-iAcj9T/Y+3DBy2J0N+yF9XQQQ8IEb5swLFzs23CdP88=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "dc9637876d0dcc8c9e5e22986b857632effeb727", + "rev": "85dbfc7aaf52ecb755f87e577ddbe6dbbdbc1054", "type": "github" }, "original": { @@ -80,11 +80,11 @@ ] }, "locked": { - "lastModified": 1750779888, - "narHash": "sha256-wibppH3g/E2lxU43ZQHC5yA/7kIKLGxVEnsnVK1BtRg=", + "lastModified": 1754416808, + "narHash": "sha256-c6yg0EQ9xVESx6HGDOCMcyRSjaTpNJP10ef+6fRcofA=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "16ec914f6fb6f599ce988427d9d94efddf25fe6d", + "rev": "9c52372878df6911f9afc1e2a1391f55e4dfc864", "type": "github" }, "original": { diff --git a/src/args.rs b/src/args.rs index 622180e..70bde87 100644 --- a/src/args.rs +++ b/src/args.rs @@ -95,6 +95,13 @@ pub(crate) enum AlbumsCommands { /// List all albums #[serde(rename = "list")] List {}, + /// List all assets that belong to a specific album + #[serde(rename = "list-assets")] + ListAssets { + /// Name of the album to list assets for + #[arg(long)] + album: String, + }, } #[derive(Serialize, Subcommand)] diff --git a/src/commands/list_album_assets.rs b/src/commands/list_album_assets.rs new file mode 100644 index 0000000..5071b25 --- /dev/null +++ b/src/commands/list_album_assets.rs @@ -0,0 +1,38 @@ +use crate::{ + actions::{ + action::Action, fetch_album_assets::FetchAlbumAssets, fetch_all_albums::FetchAllAlbums, + }, + context::Context, +}; +use color_eyre::eyre::{eyre, Result}; +use tabled::{settings::Style, Table, Tabled}; + +#[derive(Tabled)] +struct AssetRow { + #[tabled(rename = "Path")] + original_file_path: String, +} + +pub async fn list_album_assets(ctx: Context, album_name: &str) -> Result<()> { + let albums = FetchAllAlbums::new(()).execute(&ctx).await?; + + let album = albums + .into_iter() + .find(|a| a.name == album_name) + .ok_or_else(|| eyre!("Album not found: {}", album_name))?; + + let mut assets: Vec<_> = FetchAlbumAssets::new(album) + .execute(&ctx) + .await? + .into_iter() + .map(|asset| AssetRow { + original_file_path: asset.original_path.to_string_lossy().to_string(), + }) + .collect(); + + assets.sort_by_key(|row| row.original_file_path.clone()); + + println!("{}", Table::new(assets).with(Style::rounded())); + + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3924e81..ae72806 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,6 +1,7 @@ pub mod auto_create_albums; pub mod delete_albums; pub mod delete_assets; +pub mod list_album_assets; pub mod list_albums; pub mod list_assets; pub mod list_libraries; diff --git a/src/main.rs b/src/main.rs index 7226bc5..05596a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(renamed_and_removed_lints)] // https://github.com/oxidecomputer/progenitor/issues/1169 include!(concat!(env!("OUT_DIR"), "/client.rs")); #[cfg(test)] @@ -16,6 +17,7 @@ use color_eyre::Section; use commands::auto_create_albums::auto_create_albums; use commands::delete_albums::delete_albums; use commands::delete_assets::delete_assets; +use commands::list_album_assets::list_album_assets; use commands::list_albums::list_albums; use commands::list_assets::list_assets; use commands::list_libraries::list_libraries; @@ -86,6 +88,7 @@ async fn main() -> Result<()> { } => auto_create_albums(ctx, album_name_separator.to_string()).await, AlbumsCommands::Delete { empty } => delete_albums(ctx, *empty).await, AlbumsCommands::List {} => list_albums(ctx).await, + AlbumsCommands::ListAssets { album } => list_album_assets(ctx, album).await, }, Commands::Assets { assets_command } => match assets_command { AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,