|
| 1 | +use clap::*; |
| 2 | +use config::Config; |
| 3 | +use std::fs; |
| 4 | + |
1 | 5 | fn main() { |
2 | | - println!("Hello, world!"); |
| 6 | + let init_command = command!() |
| 7 | + .name("init") |
| 8 | + .about("Initializing a Redvin node.") |
| 9 | + .arg( |
| 10 | + Arg::new("working-directory") |
| 11 | + .long("working-directory") |
| 12 | + .short('w') |
| 13 | + .help("Working directory is the path for saving relay, peers data and some other stuff for managing node.") |
| 14 | + .aliases(["workdir", "wdir", "workingdirectory", "workingdir", "wdirectory"]) |
| 15 | + .required(true) |
| 16 | + ); |
| 17 | + |
| 18 | + let start_command = command!() |
| 19 | + .name("start") |
| 20 | + .about("Starting a Redvin instance by passing a working directory."); |
| 21 | + |
| 22 | + let root_command = command!() |
| 23 | + .about("Redvin is an IPNN implementation in rust, helping to build decentralized future.") |
| 24 | + .subcommand(init_command) |
| 25 | + .subcommand(start_command) |
| 26 | + .get_matches(); |
| 27 | + |
| 28 | + match root_command.subcommand() { |
| 29 | + Some(subcommand) => { |
| 30 | + if subcommand.0 == "init" { |
| 31 | + let dir_builder = fs::DirBuilder::new(); |
| 32 | + |
| 33 | + let working_directory = subcommand |
| 34 | + .1 |
| 35 | + .get_one::<String>("working-directory") |
| 36 | + .expect("invalid working directory path."); |
| 37 | + |
| 38 | + dir_builder |
| 39 | + .create(working_directory) |
| 40 | + .expect("can not create working directory."); |
| 41 | + |
| 42 | + let config_path = format!("{}/config.toml", working_directory); |
| 43 | + fs::write(config_path, Config::default_file()) |
| 44 | + .expect("can not create config file on working directory."); |
| 45 | + } else if subcommand.0 == "start" { |
| 46 | + println!("not implemented yet!") |
| 47 | + } |
| 48 | + } |
| 49 | + None => { |
| 50 | + println!("please use `redvin --help`") |
| 51 | + } |
| 52 | + } |
3 | 53 | } |
0 commit comments