Skip to content

Commit 0a945c3

Browse files
committed
add a notion of home directory
1 parent 3d79561 commit 0a945c3

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
@@ -1767,17 +1767,21 @@ impl ClientOptions {
17671767
.unwrap_or_default()
17681768
}
17691769

1770-
fn config_path() -> Result<PathBuf, Error> {
1771-
let mut config_dir = dirs::config_dir().ok_or_else(|| anyhow!(
1770+
fn config_path(&self, file: &str) -> Result<PathBuf, Error> {
1771+
let mut path = self.context_options.home_directory.clone().or_else(dirs::config_dir).ok_or_else(|| anyhow!(
17721772
"Default wallet directory is not supported in this platform: please specify storage and wallet paths"
17731773
))?;
1774-
config_dir.push("linera");
1775-
if !config_dir.exists() {
1776-
debug!("Creating default wallet directory {}", config_dir.display());
1777-
fs_err::create_dir_all(&config_dir)?;
1774+
path.push("linera");
1775+
if let Some(name) = &self.context_options.with_wallet {
1776+
path.push(name);
17781777
}
1779-
info!("Using default wallet directory {}", config_dir.display());
1780-
Ok(config_dir)
1778+
if !path.exists() {
1779+
debug!("Creating default wallet directory {}", path.display());
1780+
fs_err::create_dir_all(&path)?;
1781+
}
1782+
path.push(file);
1783+
info!("Using wallet path {}", path.display());
1784+
Ok(path)
17811785
}
17821786

17831787
fn storage_config(&self) -> Result<StorageConfig, Error> {
@@ -1787,14 +1791,15 @@ impl ClientOptions {
17871791
let suffix = self.suffix();
17881792
let storage_env_var = env::var(format!("LINERA_STORAGE{suffix}")).ok();
17891793
if let Some(config) = storage_env_var {
1794+
warn!("LINERA_STORAGE_* is deprecated. Use --with-wallet=NAME or --storage=CONFIG instead.");
17901795
return config.parse();
17911796
}
17921797
cfg_if::cfg_if! {
17931798
if #[cfg(feature = "rocksdb")] {
17941799
let spawn_mode =
17951800
linera_views::rocks_db::RocksDbSpawnMode::get_spawn_mode_from_runtime();
17961801
let inner_storage_config = linera_service::storage::InnerStorageConfig::RocksDb {
1797-
path: Self::config_path()?.join("wallet.db"),
1802+
path: self.config_path("wallet.db")?,
17981803
spawn_mode,
17991804
};
18001805
let namespace = "default".to_string();
@@ -1810,28 +1815,30 @@ impl ClientOptions {
18101815

18111816
fn wallet_path(&self) -> Result<PathBuf, Error> {
18121817
if let Some(path) = &self.context_options.wallet_state_path {
1818+
warn!("Option --wallet is deprecated. Use --with-wallet=NAME instead.");
18131819
return Ok(path.clone());
18141820
}
18151821
let suffix = self.suffix();
18161822
let wallet_env_var = env::var(format!("LINERA_WALLET{suffix}")).ok();
18171823
if let Some(path) = wallet_env_var {
1824+
warn!("LINERA_WALLET_* is deprecated. Use --with-wallet=NAME instead.");
18181825
return Ok(path.parse()?);
18191826
}
1820-
let config_path = Self::config_path()?;
1821-
Ok(config_path.join("wallet.json"))
1827+
self.config_path("wallet.json")
18221828
}
18231829

18241830
fn keystore_path(&self) -> Result<PathBuf, Error> {
18251831
if let Some(path) = &self.context_options.keystore_path {
1832+
warn!("Option --keystore is deprecated. Use --with-wallet=NAME instead.");
18261833
return Ok(path.clone());
18271834
}
18281835
let suffix = self.suffix();
18291836
let keystore_env_var = env::var(format!("LINERA_KEYSTORE{suffix}")).ok();
18301837
if let Some(path) = keystore_env_var {
1838+
warn!("LINERA_KEYSTORE_* is deprecated. Use --with-wallet=NAME instead.");
18311839
return Ok(path.parse()?);
18321840
}
1833-
let config_path = Self::config_path()?;
1834-
Ok(config_path.join("keystore.json"))
1841+
self.config_path("keystore.json")
18351842
}
18361843

18371844
pub fn create_wallet(

0 commit comments

Comments
 (0)