Files
authentik/website/scripts/docsmg/src/main.rs
Bama ff53bccc0f website/scripts/docsmg: final version (#11501)
* add docsmg tool

* moved to the correct scripts directory

* removed test files

* added install script and readme draft to docsmg

* fix install script

* fixed issues

* Revert "fixed issues"

This reverts commit a51192025f.

* Revert "Revert "fixed issues""

This reverts commit ab68918fea.

* added dotenv and updated readme

* fixed install script

* update readme to ensure that new installers of rust have envs loaded

* changed docsmg from using .env to docsmg.env

* fixed docsmg to fix internal links in file

* fixed docsmg migrate not making directories to file

* fixed docsmg migrate trying to read pngs to string

* did stuff

* fix links

* fix links 2

* fix links 3

* fix links

* fix links

* fix links

* fix links

* fix links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed links

* update docsmg fixing links

* update docsmg fixing links

* update docsmg fixing links

* update docsmg removing empty directories

* remove changed docs

* Revert "remove changed docs"

This reverts commit 2e21a5bac8.

* remove changed docs

* fixed readme

---------

Signed-off-by: Tana M Berry <tanamarieberry@yahoo.com>
Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
2024-09-26 07:32:31 -05:00

87 lines
2.2 KiB
Rust

use std::{fs, path::PathBuf};
use clap::{Parser, Subcommand};
mod generate;
mod links;
mod migrate;
mod migratefile;
mod r#move;
mod hackyfixes;
#[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 _ = dotenv::from_filename("./docsmg.env");
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
}