Make use of FilesystemDefaults when constructing migrate commands

This commit is contained in:
asonix 2023-06-19 15:04:36 -05:00
parent a3a986638d
commit 1214b51ad7
3 changed files with 31 additions and 16 deletions

View File

@ -417,17 +417,16 @@ $ pict-rs \
-p /path/to/sled-repo -p /path/to/sled-repo
``` ```
~~If you are running the docker container with default paths, it can be simplified to the following:~~ 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_
```bash ```bash
# pict-rs \ $ pict-rs \
# filesystem \ filesystem \
# object-storage \ object-storage \
# -e https://object-storage-endpoint \ -e https://object-storage-endpoint \
# -b bucket-name \ -b bucket-name \
# -r region \ -r region \
# -a access-key \ -a access-key \
# -s secret-key -s secret-key
``` ```
_This command must be run while pict-rs is offline._ _This command must be run while pict-rs is offline._

View File

@ -551,7 +551,7 @@ enum MigrateStoreInner {
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct MigrateFilesystem { struct MigrateFilesystem {
#[command(flatten)] #[command(flatten)]
from: crate::config::primitives::Filesystem, from: Filesystem,
#[command(subcommand)] #[command(subcommand)]
to: MigrateStoreInner, to: MigrateStoreInner,
@ -561,7 +561,7 @@ struct MigrateFilesystem {
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct MigrateFilesystemInner { struct MigrateFilesystemInner {
#[command(flatten)] #[command(flatten)]
to: crate::config::primitives::Filesystem, to: Filesystem,
#[command(subcommand)] #[command(subcommand)]
repo: Option<Repo>, repo: Option<Repo>,
@ -619,10 +619,10 @@ enum Repo {
/// Configuration for filesystem media storage /// Configuration for filesystem media storage
#[derive(Clone, Debug, Parser, serde::Serialize)] #[derive(Clone, Debug, Parser, serde::Serialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
struct Filesystem { pub(super) struct Filesystem {
/// The path to store uploaded media /// The path to store uploaded media
#[arg(short, long)] #[arg(short, long)]
path: Option<PathBuf>, pub(super) path: Option<PathBuf>,
} }
/// Configuration for Object Storage /// Configuration for Object Storage

View File

@ -101,13 +101,13 @@ struct SledDefaults {
#[derive(Clone, Debug, serde::Serialize)] #[derive(Clone, Debug, serde::Serialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[serde(tag = "type")] #[serde(tag = "type")]
enum StoreDefaults { pub(super) enum StoreDefaults {
Filesystem(FilesystemDefaults), Filesystem(FilesystemDefaults),
} }
#[derive(Clone, Debug, serde::Serialize)] #[derive(Clone, Debug, serde::Serialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
struct FilesystemDefaults { pub(super) struct FilesystemDefaults {
path: PathBuf, path: PathBuf,
} }
@ -221,3 +221,19 @@ impl Default for FilesystemDefaults {
} }
} }
} }
impl From<crate::config::commandline::Filesystem> 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<crate::config::commandline::Filesystem> for crate::config::primitives::Store {
fn from(value: crate::config::commandline::Filesystem) -> Self {
crate::config::primitives::Store::Filesystem(value.into())
}
}