website/scripts: Add docsmg migration tool (#10658)
* add docsmg tool * moved to the correct scripts directory * removed test files
This commit is contained in:
83
website/scripts/docsmg/src/main.rs
Normal file
83
website/scripts/docsmg/src/main.rs
Normal file
@ -0,0 +1,83 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
mod generate;
|
||||
mod migrate;
|
||||
mod migratefile;
|
||||
mod r#move;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[arg(long, env, default_value = "./")]
|
||||
migrate_path: PathBuf,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Move {
|
||||
old_path: PathBuf,
|
||||
new_path: PathBuf,
|
||||
},
|
||||
Migrate {
|
||||
#[arg(long, name = "FILE", default_value = "./migratefile")]
|
||||
migratefile: PathBuf,
|
||||
|
||||
#[arg(short, long)]
|
||||
quiet: bool,
|
||||
},
|
||||
Unmigrate {
|
||||
#[arg(long, name = "FILE", default_value = "./migratefile")]
|
||||
migratefile: PathBuf,
|
||||
|
||||
#[arg(short, long)]
|
||||
quiet: bool,
|
||||
},
|
||||
Generate {
|
||||
#[arg(long, name = "FILE")]
|
||||
migratefile: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Commands::Move { old_path, new_path } => r#move::r#move(old_path, new_path),
|
||||
Commands::Migrate { migratefile, quiet } => {
|
||||
migrate::migrate(quiet, migratefile, cli.migrate_path)
|
||||
}
|
||||
Commands::Unmigrate { migratefile, quiet } => {
|
||||
migrate::unmigrate(quiet, migratefile, cli.migrate_path)
|
||||
}
|
||||
Commands::Generate { migratefile } => generate::generate(migratefile, cli.migrate_path),
|
||||
}
|
||||
}
|
||||
|
||||
fn recurse_directory(path: PathBuf) -> Vec<PathBuf> {
|
||||
let paths = fs::read_dir(path).expect("path to exist");
|
||||
let mut final_paths = vec![];
|
||||
for path in paths {
|
||||
match path {
|
||||
Ok(path) => {
|
||||
if !path.path().is_file() && !path.path().is_dir() {
|
||||
continue;
|
||||
} // dont go any further if not a file or directory
|
||||
let is_dir = path.path().is_dir();
|
||||
let path = path.path();
|
||||
|
||||
if is_dir {
|
||||
let mut paths = recurse_directory(path);
|
||||
final_paths.append(&mut paths);
|
||||
} else {
|
||||
final_paths.push(path);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
final_paths
|
||||
}
|
Reference in New Issue
Block a user