Skip to content

Commit 5632046

Browse files
committed
add a notion of home directory
1 parent a567ac8 commit 5632046

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

linera-client/src/client_options.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ util::impl_from_infallible!(Error);
4242

4343
#[derive(Clone, clap::Parser)]
4444
pub struct ClientContextOptions {
45-
/// Sets the file storing the private state of user chains (an empty one will be created if missing)
45+
/// DEPRECATED: Use --with-wallet=NAME instead. Sets the file
46+
/// storing the private state of user chains (an empty one will be created if missing)
4647
#[arg(long = "wallet")]
4748
pub wallet_state_path: Option<PathBuf>,
4849

49-
/// Sets the file storing the keystore state.
50+
/// DEPRECATED: Use --with-wallet=NAME instead. Sets the file
51+
/// storing the keystore state.
5052
#[arg(long = "keystore")]
5153
pub keystore_path: Option<PathBuf>,
5254

53-
/// Given an ASCII alphanumeric parameter `X`, read the wallet state and the wallet
54-
/// storage config from the environment variables `LINERA_WALLET_{X}` and
55-
/// `LINERA_STORAGE_{X}` instead of `LINERA_WALLET` and
56-
/// `LINERA_STORAGE`.
57-
#[arg(long, short = 'w', value_parser = util::parse_ascii_alphanumeric_string)]
55+
/// Sets the home directory for storing Linera wallets. Alternatively, one may set the
56+
/// environment variable LINERA_HOME.
57+
#[arg(long, env = "LINERA_HOME")]
58+
pub home_directory: Option<PathBuf>,
59+
60+
/// Name of the wallet to be used. Data will be stored in the corresponding
61+
/// subdirectory of the home directory -- unless other (deprecated) options are
62+
/// used.
63+
#[arg(long, short = 'w', value_name = "NAME", value_parser = util::parse_ascii_alphanumeric_string)]
5864
pub with_wallet: Option<String>,
5965

6066
/// Timeout for sending queries (milliseconds)

linera-service/src/cli/main.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,17 +1755,21 @@ impl ClientOptions {
17551755
.unwrap_or_default()
17561756
}
17571757

1758-
fn config_path() -> Result<PathBuf, Error> {
1759-
let mut config_dir = dirs::config_dir().ok_or_else(|| anyhow!(
1758+
fn config_path(&self, file: &str) -> Result<PathBuf, Error> {
1759+
let mut path = self.context_options.home_directory.clone().or_else(dirs::config_dir).ok_or_else(|| anyhow!(
17601760
"Default wallet directory is not supported in this platform: please specify storage and wallet paths"
17611761
))?;
1762-
config_dir.push("linera");
1763-
if !config_dir.exists() {
1764-
debug!("Creating default wallet directory {}", config_dir.display());
1765-
fs_err::create_dir_all(&config_dir)?;
1762+
path.push("linera");
1763+
if let Some(name) = &self.context_options.with_wallet {
1764+
path.push(name);
17661765
}
1767-
info!("Using default wallet directory {}", config_dir.display());
1768-
Ok(config_dir)
1766+
if !path.exists() {
1767+
debug!("Creating default wallet directory {}", path.display());
1768+
fs_err::create_dir_all(&path)?;
1769+
}
1770+
path.push(file);
1771+
info!("Using wallet path {}", path.display());
1772+
Ok(path)
17691773
}
17701774

17711775
fn storage_config(&self) -> Result<StorageConfig, Error> {
@@ -1775,14 +1779,15 @@ impl ClientOptions {
17751779
let suffix = self.suffix();
17761780
let storage_env_var = env::var(format!("LINERA_STORAGE{suffix}")).ok();
17771781
if let Some(config) = storage_env_var {
1782+
warn!("LINERA_STORAGE_* is deprecated. Use --with-wallet=NAME or --storage=CONFIG instead.");
17781783
return config.parse();
17791784
}
17801785
cfg_if::cfg_if! {
17811786
if #[cfg(feature = "rocksdb")] {
17821787
let spawn_mode =
17831788
linera_views::rocks_db::RocksDbSpawnMode::get_spawn_mode_from_runtime();
17841789
let inner_storage_config = linera_service::storage::InnerStorageConfig::RocksDb {
1785-
path: Self::config_path()?.join("wallet.db"),
1790+
path: self.config_path("wallet.db")?,
17861791
spawn_mode,
17871792
};
17881793
let namespace = "default".to_string();
@@ -1798,28 +1803,30 @@ impl ClientOptions {
17981803

17991804
fn wallet_path(&self) -> Result<PathBuf, Error> {
18001805
if let Some(path) = &self.context_options.wallet_state_path {
1806+
warn!("Option --wallet is deprecated. Use --with-wallet=NAME instead.");
18011807
return Ok(path.clone());
18021808
}
18031809
let suffix = self.suffix();
18041810
let wallet_env_var = env::var(format!("LINERA_WALLET{suffix}")).ok();
18051811
if let Some(path) = wallet_env_var {
1812+
warn!("LINERA_WALLET_* is deprecated. Use --with-wallet=NAME instead.");
18061813
return Ok(path.parse()?);
18071814
}
1808-
let config_path = Self::config_path()?;
1809-
Ok(config_path.join("wallet.json"))
1815+
self.config_path("wallet.json")
18101816
}
18111817

18121818
fn keystore_path(&self) -> Result<PathBuf, Error> {
18131819
if let Some(path) = &self.context_options.keystore_path {
1820+
warn!("Option --keystore is deprecated. Use --with-wallet=NAME instead.");
18141821
return Ok(path.clone());
18151822
}
18161823
let suffix = self.suffix();
18171824
let keystore_env_var = env::var(format!("LINERA_KEYSTORE{suffix}")).ok();
18181825
if let Some(path) = keystore_env_var {
1826+
warn!("LINERA_KEYSTORE_* is deprecated. Use --with-wallet=NAME instead.");
18191827
return Ok(path.parse()?);
18201828
}
1821-
let config_path = Self::config_path()?;
1822-
Ok(config_path.join("keystore.json"))
1829+
self.config_path("keystore.json")
18231830
}
18241831

18251832
pub fn create_wallet(

0 commit comments

Comments
 (0)