From 61e441976f1bd790fbac2cdcd98b930112e0a8e2 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Mon, 22 Jul 2024 15:58:26 -0400 Subject: [PATCH] Make pclientd/pcli default_home accessible when using them as libraries (#4729) ## Describe your changes Changes the location and exposure of the `default_home` functions in `pcli`/`pclientd` so they can be accessed when used as libraries. ## Checklist before requesting a review - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > minor change to client code organization --- crates/bin/pcli/src/lib.rs | 10 ++++++++++ crates/bin/pcli/src/opt.rs | 10 +--------- crates/bin/pclientd/src/lib.rs | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/bin/pcli/src/lib.rs b/crates/bin/pcli/src/lib.rs index 3dc92ffb4b..1faf352016 100644 --- a/crates/bin/pcli/src/lib.rs +++ b/crates/bin/pcli/src/lib.rs @@ -4,6 +4,8 @@ use { crate::{command::*, config::PcliConfig}, anyhow::Result, + camino::Utf8PathBuf, + directories::ProjectDirs, futures::StreamExt, penumbra_proto::{ box_grpc_svc::BoxGrpcService, custody::v1::custody_service_client::CustodyServiceClient, @@ -81,3 +83,11 @@ impl App { Ok(()) } } + +pub fn default_home() -> Utf8PathBuf { + let path = ProjectDirs::from("zone", "penumbra", "pcli") + .expect("Failed to get platform data dir") + .data_dir() + .to_path_buf(); + Utf8PathBuf::from_path_buf(path).expect("Platform default data dir was not UTF-8") +} diff --git a/crates/bin/pcli/src/opt.rs b/crates/bin/pcli/src/opt.rs index 9c87771a49..d55e3ca2d6 100644 --- a/crates/bin/pcli/src/opt.rs +++ b/crates/bin/pcli/src/opt.rs @@ -1,12 +1,12 @@ use crate::{ config::{CustodyConfig, GovernanceCustodyConfig, PcliConfig}, + default_home, terminal::ActualTerminal, App, Command, }; use anyhow::Result; use camino::Utf8PathBuf; use clap::Parser; -use directories::ProjectDirs; use penumbra_custody::{null_kms::NullKms, soft_kms::SoftKms}; use penumbra_proto::box_grpc_svc; use penumbra_proto::{ @@ -178,11 +178,3 @@ impl Opt { Ok((app, self.cmd)) } } - -fn default_home() -> Utf8PathBuf { - let path = ProjectDirs::from("zone", "penumbra", "pcli") - .expect("Failed to get platform data dir") - .data_dir() - .to_path_buf(); - Utf8PathBuf::from_path_buf(path).expect("Platform default data dir was not UTF-8") -} diff --git a/crates/bin/pclientd/src/lib.rs b/crates/bin/pclientd/src/lib.rs index afab0a80d2..5b4be2f4b0 100644 --- a/crates/bin/pclientd/src/lib.rs +++ b/crates/bin/pclientd/src/lib.rs @@ -66,7 +66,7 @@ impl PclientdConfig { } } -fn default_home() -> Utf8PathBuf { +pub fn default_home() -> Utf8PathBuf { let path = ProjectDirs::from("zone", "penumbra", "pclientd") .expect("Failed to get platform data dir") .data_dir()