Skip to main content

soon_migrate/
cli.rs

1//! Command-line interface module for the SOON Network migration tool.
2//!
3//! This module handles command-line argument parsing and configuration
4//! for the migration process.
5
6use clap::{Arg, ArgAction, Command};
7
8/// Configuration options for the migration tool
9#[derive(Debug)]
10pub struct Config {
11    /// Path to the Anchor project directory
12    pub path: String,
13    /// Whether to perform a dry run without making changes
14    pub dry_run: bool,
15    /// Whether to enable verbose output
16    pub verbose: bool,
17    /// Whether to restore from a backup
18    pub restore: bool,
19    /// Whether to show the APRO integration guide
20    pub show_guide: bool,
21    /// Whether to only run oracle detection
22    pub oracle_only: bool,
23}
24
25impl Config {
26    /// Create a new Config by parsing command line arguments
27    ///
28    /// # Returns
29    /// A new `Config` instance with options parsed from command line arguments
30    pub fn new() -> Self {
31        let matches = Command::new("soon-migrate")
32            .version("0.2.0")
33            .author("Akshat Sharma <akshatsharma0023@outlook.com>")
34            .about("Migrates Solana Anchor projects to SOON Network with oracle detection")
35            .arg(
36                Arg::new("path")
37                    .help("Path to the Anchor project")
38                    .default_value(".")
39                    .index(1),
40            )
41            .arg(
42                Arg::new("dry-run")
43                    .long("dry-run")
44                    .help("Show changes without applying them")
45                    .action(ArgAction::SetTrue),
46            )
47            .arg(
48                Arg::new("verbose")
49                    .long("verbose")
50                    .short('v')
51                    .help("Enable detailed logging")
52                    .action(ArgAction::SetTrue),
53            )
54            .arg(
55                Arg::new("restore")
56                    .long("restore")
57                    .help("Restore from backup")
58                    .action(ArgAction::SetTrue),
59            )
60            .arg(
61                Arg::new("show-guide")
62                    .long("show-guide")
63                    .help("Show detailed APRO integration guide")
64                    .action(ArgAction::SetTrue),
65            )
66            .arg(
67                Arg::new("oracle-only")
68                    .long("oracle-only")
69                    .help("Only scan for oracles, don't perform migration")
70                    .action(ArgAction::SetTrue),
71            )
72            .get_matches();
73
74        Config {
75            path: matches.get_one::<String>("path").unwrap().to_string(),
76            dry_run: matches.get_flag("dry-run"),
77            verbose: matches.get_flag("verbose"),
78            restore: matches.get_flag("restore"),
79            show_guide: matches.get_flag("show-guide"),
80            oracle_only: matches.get_flag("oracle-only"),
81        }
82    }
83}