Skip to content
Snippets Groups Projects
Commit 5ecba798 authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Hugo Trentesaux
Browse files

WIP add config

parent 93e6bf55
No related branches found
No related tags found
1 merge request!7Big refacto
...@@ -349,6 +349,18 @@ dependencies = [ ...@@ -349,6 +349,18 @@ dependencies = [
"unreachable", "unreachable",
] ]
[[package]]
name = "confy"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37668cb35145dcfaa1931a5f37fde375eeae8068b4c0d2f289da28a270b2d2c"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
...@@ -566,6 +578,26 @@ dependencies = [ ...@@ -566,6 +578,26 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "directories"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]] [[package]]
name = "downcast-rs" name = "downcast-rs"
version = "1.2.0" version = "1.2.0"
...@@ -851,6 +883,7 @@ version = "0.1.0" ...@@ -851,6 +883,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"confy",
"env_logger", "env_logger",
"futures", "futures",
"graphql_client", "graphql_client",
...@@ -2070,6 +2103,17 @@ dependencies = [ ...@@ -2070,6 +2103,17 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom 0.2.8",
"redox_syscall",
"thiserror",
]
[[package]] [[package]]
name = "ref-cast" name = "ref-cast"
version = "1.0.15" version = "1.0.15"
...@@ -3194,6 +3238,15 @@ dependencies = [ ...@@ -3194,6 +3238,15 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.6.1" version = "0.6.1"
......
...@@ -22,6 +22,7 @@ serde_json = "1.0.94" ...@@ -22,6 +22,7 @@ serde_json = "1.0.94"
sp-core = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32" } sp-core = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32" }
subxt = { git = "https://github.com/duniter/subxt.git", branch = "duniter-substrate-v0.9.32" } subxt = { git = "https://github.com/duniter/subxt.git", branch = "duniter-substrate-v0.9.32" }
tokio = { version = "1.26.0", features = ["macros"] } tokio = { version = "1.26.0", features = ["macros"] }
confy = "0.5.1"
# allows to build gcli with different predefined networks # allows to build gcli with different predefined networks
[features] [features]
......
use crate::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
version: u8,
}
impl std::default::Default for Config {
fn default() -> Self {
Self {
version: 0,
}
}
}
#[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand {
#[default]
/// Show config
Show,
}
pub fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
// match subcommand
match command {
Subcommand::Show => {
println!("{:?}", data.cfg);
}
};
Ok(())
}
...@@ -9,6 +9,8 @@ use indexer::Indexer; ...@@ -9,6 +9,8 @@ use indexer::Indexer;
pub struct Data { pub struct Data {
// command line arguments // command line arguments
pub args: Args, pub args: Args,
// config
pub cfg: conf::Config,
// rpc to substrate client // rpc to substrate client
pub client: Option<Client>, pub client: Option<Client>,
// graphql to duniter-indexer // graphql to duniter-indexer
...@@ -43,6 +45,7 @@ impl Data { ...@@ -43,6 +45,7 @@ impl Data {
pub fn new(args: Args) -> Self { pub fn new(args: Args) -> Self {
Self { Self {
args, args,
cfg: confy::load("gcli", None).expect("must be able to build config"),
token_decimals: 0, token_decimals: 0,
token_symbol: "tokens".into(), token_symbol: "tokens".into(),
..Default::default() ..Default::default()
......
mod cache; mod cache;
mod commands; mod commands;
mod conf;
mod data; mod data;
mod indexer; mod indexer;
mod keys; mod keys;
use clap::Parser; use clap::Parser;
use codec::Encode; use codec::Encode;
use confy;
use data::*; use data::*;
use keys::*; use keys::*;
use serde::Deserialize; use serde::Deserialize;
...@@ -257,12 +259,17 @@ pub enum Subcommand { ...@@ -257,12 +259,17 @@ pub enum Subcommand {
/// Indexer subcommands /// Indexer subcommands
#[clap(subcommand)] #[clap(subcommand)]
Indexer(indexer::Subcommand), Indexer(indexer::Subcommand),
/// Config subcommands
#[clap(subcommand)]
Config(conf::Subcommand),
} }
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), GcliError> { async fn main() -> Result<(), GcliError> {
// init logger
env_logger::init(); env_logger::init();
// parse argument and initialize data
let args = Args::parse(); let args = Args::parse();
let mut data = Data::new(args.clone()); let mut data = Data::new(args.clone());
...@@ -608,6 +615,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -608,6 +615,7 @@ async fn main() -> Result<(), GcliError> {
} }
} }
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?,
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?,
} }
Ok(()) Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment