1use clap::{Parser, Subcommand};
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5use crate::commands::{
6 AnalyzeCommandArgs, Command, GenerateCommand, ScanCommand, ServeCommand, TrainCommand,
7 ViewCommand,
8};
9use crate::data::DataStreamResult;
10use crate::sink::print_datastream_result;
11use scan::{ScanError, ScanResult, Scanner};
12
13use tokio_stream::StreamExt;
14
15#[derive(Parser)]
16#[command(
17 name = "rmap",
18 about = "IPv6 network scanning and analysis toolkit",
19 version = "0.1.0",
20 author = "Chase Kanipe"
21)]
22pub struct Cli {
23 #[arg(short, long, action = clap::ArgAction::Count)]
24 pub verbose: u8,
25
26 #[arg(short, long, value_name = "LOG_FILE")]
27 pub log: Option<PathBuf>,
28
29 #[command(subcommand)]
30 pub command: Commands,
31}
32
33#[derive(Subcommand, Serialize, Deserialize)]
34pub enum Commands {
35 Scan(ScanCommand),
37 Train(TrainCommand),
39 Generate(GenerateCommand),
41 Analyze(AnalyzeCommandArgs),
43 Serve(ServeCommand),
45}
46
47impl Commands {
48 pub async fn run(&self) {
49 match self {
50 Commands::Generate(cmd) => cmd.run().await.unwrap(),
51 Commands::Scan(cmd) => {
52 match cmd.run().await {
54 Ok(_) => (),
55 Err(e) => {
56 tracing::error!("{}", e);
57 return;
58 }
59 }
60 return;
61 }
62 Commands::Train(cmd) => cmd.run().await.unwrap(),
63 Commands::Analyze(cmd) => cmd.run().await.unwrap(),
64 Commands::Serve(cmd) => cmd.run().await.unwrap(),
65 };
66 }
67}