Skip to content

Commit

Permalink
feat: add command line arguments support to collectibles (#3714)
Browse files Browse the repository at this point in the history
Description
---
Add support for command line arguments to tari_collectibles.
Fallback is env var -> default value.

How Has This Been Tested?
---
Manually.
  • Loading branch information
Cifko authored Jan 18, 2022
1 parent c50a934 commit 696f2ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion applications/tari_collectibles/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ thiserror = "1.0.30"
uuid = { version = "0.8.2", features = ["serde"] }
prost = "0.9"
prost-types = "0.9"
structopt = "0.3.25"

[features]
default = [ "custom-protocol" ]
custom-protocol = [ "tauri/custom-protocol" ]
custom-protocol = [ "tauri/custom-protocol" ]
44 changes: 25 additions & 19 deletions applications/tari_collectibles/src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,39 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{env, path::PathBuf};
use std::path::PathBuf;

use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct Settings {
#[structopt(short, long, aliases = &["base_path", "base_dir", "base-dir"], env="DATA_DIR", default_value = "data")]
pub(crate) data_dir: PathBuf,
#[structopt(
short,
long,
env = "WALLET_GRPC_ADDRESS",
default_value = "localhost:18143"
)]
pub(crate) wallet_grpc_address: String,
#[structopt(
short,
long,
env = "BASE_NODE_GRPC_ADDRESS",
default_value = "localhost:18142"
)]
pub(crate) base_node_grpc_address: String,
#[structopt(
short,
long,
env = "VALIDATOR_NODE_GRPC_ADDRESS",
default_value = "localhost:18144"
)]
pub(crate) validator_node_grpc_address: String,
pub(crate) data_dir: PathBuf,
}

impl Settings {
pub fn new() -> Self {
// Self {
// wallet_grpc_address: "localhost:18143".to_string(),
// base_node_grpc_address: "localhost:18142".to_string(),
// _favourite_assets: vec!["1234".to_string()],
// }
let data_dir = env::var("DATA_DIR").unwrap_or_else(|_| "data".to_string());
let data_dir = PathBuf::from(data_dir);
// TODO: remove this, just for convenience
Self {
wallet_grpc_address: env::var("WALLET_GRPC_ADDRESS")
.unwrap_or_else(|_| "localhost:18143".to_string()),
base_node_grpc_address: env::var("BASE_NODE_GRPC_ADDRESS")
.unwrap_or_else(|_| "localhost:18142".to_string()),
validator_node_grpc_address: env::var("VALIDATOR_NODE_GRPC_ADDRESS")
.unwrap_or_else(|_| "localhost:18144".to_string()),
data_dir,
}
Self::from_args()
}
}

0 comments on commit 696f2ef

Please sign in to comment.