mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-08-02 16:11:45 +00:00
parsing
This commit is contained in:
@ -1,27 +1,61 @@
|
|||||||
use clap::{command, Arg, Command, ArgMatches};
|
use clap::{command, Arg, Command, ArgMatches};
|
||||||
|
|
||||||
use crate::coordinator;
|
#[derive(Debug)]
|
||||||
|
pub struct Coordinator {
|
||||||
|
|
||||||
pub struct cli_settings {
|
}
|
||||||
pub coordinator: bool,
|
|
||||||
pub maker: bool,
|
#[derive(Debug)]
|
||||||
pub taker: bool,
|
pub struct TraderSettings {
|
||||||
pub c_endpoint: String,
|
pub electrum_endpoint: String,
|
||||||
pub electrum_ep: String,
|
pub coordinator_endpoint: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum CliSettings {
|
||||||
|
Coordinator(Coordinator),
|
||||||
|
Taker(TraderSettings),
|
||||||
|
Maker(TraderSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ArgMatchesParser {
|
trait ArgMatchesParser {
|
||||||
|
fn parse_into_enum(&self) -> CliSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_cli_args() -> ArgMatches {
|
impl ArgMatchesParser for ArgMatches {
|
||||||
|
fn parse_into_enum(&self) -> CliSettings {
|
||||||
|
if let Some(_mode) = self.subcommand_matches("coordinator") {
|
||||||
|
CliSettings::Coordinator(Coordinator { })
|
||||||
|
} else if let Some(_mode) = self.subcommand_matches("trader") {
|
||||||
|
let trader_settings = TraderSettings {
|
||||||
|
coordinator_endpoint: self.get_one::<String>("coordinator-ep")
|
||||||
|
.expect("Coordinator endpoint not provided!").clone(),
|
||||||
|
electrum_endpoint: self.get_one::<String>("electrum-ep")
|
||||||
|
.expect("Electrum endpoint not provided").clone()
|
||||||
|
};
|
||||||
|
if self.contains_id("maker") {
|
||||||
|
CliSettings::Maker( trader_settings )
|
||||||
|
} else if self.contains_id("taker") {
|
||||||
|
CliSettings::Taker( trader_settings )
|
||||||
|
} else {
|
||||||
|
panic!("Wrong arguments for Trader mode!")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("Select either coordinator or trader mode!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_cli_args() -> CliSettings {
|
||||||
command!()
|
command!()
|
||||||
.about("RoboSats taproot onchain trade pipeline CLI demonstrator. Don't use with real funds.")
|
.about("RoboSats taproot onchain trade pipeline CLI demonstrator. Don't use with real funds.")
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("coordinator")
|
Command::new("coordinator")
|
||||||
|
.about("Run in coordinator mode.")
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("trader")
|
Command::new("trader")
|
||||||
|
.about("Two available trader modes: Maker and Taker. Select one and provide Coordinator and Electum endpoint")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("taker")
|
Arg::new("taker")
|
||||||
.short('t')
|
.short('t')
|
||||||
@ -39,12 +73,21 @@ pub fn parse_cli_args() -> ArgMatches {
|
|||||||
.conflicts_with("taker")
|
.conflicts_with("taker")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("endpoint")
|
Arg::new("coordinator-ep")
|
||||||
.short('p')
|
.short('p')
|
||||||
.long("endpoint")
|
.long("endpoint")
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Communication endpoint of the coordinator to connect to")
|
.help("Communication endpoint of the coordinator to connect to")
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("electrum-ep")
|
||||||
|
.short('e')
|
||||||
|
.long("electrum")
|
||||||
|
.required(true)
|
||||||
|
.help("URL of the electrum endpoint")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
.arg_required_else_help(true)
|
||||||
.get_matches()
|
.get_matches()
|
||||||
|
.parse_into_enum()
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,5 @@ use cli::parse_cli_args;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli_args = parse_cli_args();
|
let cli_args = parse_cli_args();
|
||||||
|
dbg!(cli_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use clap to parse mode (taker, maker or coordinator), communication endpoint (URL or PID or something else), electrum server
|
|
||||||
// https://www.youtube.com/watch?v=Ot3qCA3Iv_8
|
|
||||||
|
Reference in New Issue
Block a user