From 1214b51ad7479f207d6f0c35705d7f1ec00af710 Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 19 Jun 2023 15:04:36 -0500 Subject: [PATCH] Make use of FilesystemDefaults when constructing migrate commands --- README.md | 19 +++++++++---------- src/config/commandline.rs | 8 ++++---- src/config/defaults.rs | 20 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a24331f..cb2b792 100644 --- a/README.md +++ b/README.md @@ -417,17 +417,16 @@ $ pict-rs \ -p /path/to/sled-repo ``` -~~If you are running the docker container with default paths, it can be simplified to the following:~~ -_currently broken, will fix for next release candidate_ +If you are running the docker container with default paths, it can be simplified to the following: ```bash -# pict-rs \ -# filesystem \ -# object-storage \ -# -e https://object-storage-endpoint \ -# -b bucket-name \ -# -r region \ -# -a access-key \ -# -s secret-key +$ pict-rs \ + filesystem \ + object-storage \ + -e https://object-storage-endpoint \ + -b bucket-name \ + -r region \ + -a access-key \ + -s secret-key ``` _This command must be run while pict-rs is offline._ diff --git a/src/config/commandline.rs b/src/config/commandline.rs index 327ff57..03b1a15 100644 --- a/src/config/commandline.rs +++ b/src/config/commandline.rs @@ -551,7 +551,7 @@ enum MigrateStoreInner { #[derive(Debug, Parser)] struct MigrateFilesystem { #[command(flatten)] - from: crate::config::primitives::Filesystem, + from: Filesystem, #[command(subcommand)] to: MigrateStoreInner, @@ -561,7 +561,7 @@ struct MigrateFilesystem { #[derive(Debug, Parser)] struct MigrateFilesystemInner { #[command(flatten)] - to: crate::config::primitives::Filesystem, + to: Filesystem, #[command(subcommand)] repo: Option, @@ -619,10 +619,10 @@ enum Repo { /// Configuration for filesystem media storage #[derive(Clone, Debug, Parser, serde::Serialize)] #[serde(rename_all = "snake_case")] -struct Filesystem { +pub(super) struct Filesystem { /// The path to store uploaded media #[arg(short, long)] - path: Option, + pub(super) path: Option, } /// Configuration for Object Storage diff --git a/src/config/defaults.rs b/src/config/defaults.rs index a1e68e1..75a225d 100644 --- a/src/config/defaults.rs +++ b/src/config/defaults.rs @@ -101,13 +101,13 @@ struct SledDefaults { #[derive(Clone, Debug, serde::Serialize)] #[serde(rename_all = "snake_case")] #[serde(tag = "type")] -enum StoreDefaults { +pub(super) enum StoreDefaults { Filesystem(FilesystemDefaults), } #[derive(Clone, Debug, serde::Serialize)] #[serde(rename_all = "snake_case")] -struct FilesystemDefaults { +pub(super) struct FilesystemDefaults { path: PathBuf, } @@ -221,3 +221,19 @@ impl Default for FilesystemDefaults { } } } + +impl From for crate::config::primitives::Filesystem { + fn from(value: crate::config::commandline::Filesystem) -> Self { + Self { + path: value + .path + .unwrap_or_else(|| FilesystemDefaults::default().path), + } + } +} + +impl From for crate::config::primitives::Store { + fn from(value: crate::config::commandline::Filesystem) -> Self { + crate::config::primitives::Store::Filesystem(value.into()) + } +}