Skip to content

Commit 03a5219

Browse files
committed
add a notion of home directory
1 parent df0d771 commit 03a5219

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
@@ -45,19 +45,25 @@ util::impl_from_infallible!(Error);
4545

4646
#[derive(Clone, clap::Parser)]
4747
pub struct ClientContextOptions {
48-
/// Sets the file storing the private state of user chains (an empty one will be created if missing)
48+
/// DEPRECATED: Use --with-wallet=NAME instead. Sets the file
49+
/// storing the private state of user chains (an empty one will be created if missing)
4950
#[arg(long = "wallet")]
5051
pub wallet_state_path: Option<PathBuf>,
5152

52-
/// Sets the file storing the keystore state.
53+
/// DEPRECATED: Use --with-wallet=NAME instead. Sets the file
54+
/// storing the keystore state.
5355
#[arg(long = "keystore")]
5456
pub keystore_path: Option<PathBuf>,
5557

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

6369
/// 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
@@ -1814,17 +1814,21 @@ impl ClientOptions {
18141814
.unwrap_or_default()
18151815
}
18161816

1817-
fn config_path() -> Result<PathBuf, Error> {
1818-
let mut config_dir = dirs::config_dir().ok_or_else(|| anyhow!(
1817+
fn config_path(&self, file: &str) -> Result<PathBuf, Error> {
1818+
let mut path = self.context_options.home_directory.clone().or_else(dirs::config_dir).ok_or_else(|| anyhow!(
18191819
"Default wallet directory is not supported in this platform: please specify storage and wallet paths"
18201820
))?;
1821-
config_dir.push("linera");
1822-
if !config_dir.exists() {
1823-
debug!("Creating default wallet directory {}", config_dir.display());
1824-
fs_err::create_dir_all(&config_dir)?;
1821+
path.push("linera");
1822+
if let Some(name) = &self.context_options.with_wallet {
1823+
path.push(name);
18251824
}
1826-
info!("Using default wallet directory {}", config_dir.display());
1827-
Ok(config_dir)
1825+
if !path.exists() {
1826+
debug!("Creating default wallet directory {}", path.display());
1827+
fs_err::create_dir_all(&path)?;
1828+
}
1829+
path.push(file);
1830+
info!("Using wallet path {}", path.display());
1831+
Ok(path)
18281832
}
18291833

18301834
fn storage_config(&self) -> Result<StorageConfig, Error> {
@@ -1834,14 +1838,15 @@ impl ClientOptions {
18341838
let suffix = self.suffix();
18351839
let storage_env_var = env::var(format!("LINERA_STORAGE{suffix}")).ok();
18361840
if let Some(config) = storage_env_var {
1841+
warn!("LINERA_STORAGE_* is deprecated. Use --with-wallet=NAME or --storage=CONFIG instead.");
18371842
return config.parse();
18381843
}
18391844
cfg_if::cfg_if! {
18401845
if #[cfg(feature = "rocksdb")] {
18411846
let spawn_mode =
18421847
linera_views::rocks_db::RocksDbSpawnMode::get_spawn_mode_from_runtime();
18431848
let inner_storage_config = linera_service::storage::InnerStorageConfig::RocksDb {
1844-
path: Self::config_path()?.join("wallet.db"),
1849+
path: self.config_path("wallet.db")?,
18451850
spawn_mode,
18461851
};
18471852
let namespace = "default".to_string();
@@ -1857,28 +1862,30 @@ impl ClientOptions {
18571862

18581863
fn wallet_path(&self) -> Result<PathBuf, Error> {
18591864
if let Some(path) = &self.context_options.wallet_state_path {
1865+
warn!("Option --wallet is deprecated. Use --with-wallet=NAME instead.");
18601866
return Ok(path.clone());
18611867
}
18621868
let suffix = self.suffix();
18631869
let wallet_env_var = env::var(format!("LINERA_WALLET{suffix}")).ok();
18641870
if let Some(path) = wallet_env_var {
1871+
warn!("LINERA_WALLET_* is deprecated. Use --with-wallet=NAME instead.");
18651872
return Ok(path.parse()?);
18661873
}
1867-
let config_path = Self::config_path()?;
1868-
Ok(config_path.join("wallet.json"))
1874+
self.config_path("wallet.json")
18691875
}
18701876

18711877
fn keystore_path(&self) -> Result<PathBuf, Error> {
18721878
if let Some(path) = &self.context_options.keystore_path {
1879+
warn!("Option --keystore is deprecated. Use --with-wallet=NAME instead.");
18731880
return Ok(path.clone());
18741881
}
18751882
let suffix = self.suffix();
18761883
let keystore_env_var = env::var(format!("LINERA_KEYSTORE{suffix}")).ok();
18771884
if let Some(path) = keystore_env_var {
1885+
warn!("LINERA_KEYSTORE_* is deprecated. Use --with-wallet=NAME instead.");
18781886
return Ok(path.parse()?);
18791887
}
1880-
let config_path = Self::config_path()?;
1881-
Ok(config_path.join("keystore.json"))
1888+
self.config_path("keystore.json")
18821889
}
18831890

18841891
pub fn create_wallet(

0 commit comments

Comments
 (0)