Files
authentik/website/scripts/docsmg/src/migratefile.rs
Bama ca7705689d website/scripts/docsmg: Bug fixes (#10668)
* 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
2024-07-28 21:32:29 -05:00

36 lines
1.0 KiB
Rust

use std::{fs::read_to_string, path::PathBuf};
pub fn read_migrate_file(file: PathBuf) -> anyhow::Result<Vec<(PathBuf, PathBuf)>> {
let contents = read_to_string(file)?;
let lines: Vec<String> = contents
.split('\n')
.map(|x| x.to_owned())
.filter(|x| x != "")
.collect();
let migrations = lines
.iter()
.filter_map(|x| x.split_once(" -> "))
.map(|x| {
(
x.0.parse().expect("a valid path"),
x.1.parse().expect("a valid path"),
)
})
.collect::<Vec<_>>();
Ok(migrations)
}
pub fn read_migrate_file_left_side(file: PathBuf) -> anyhow::Result<Vec<PathBuf>> {
let contents = read_to_string(file)?;
let lines: Vec<String> = contents
.split('\n')
.map(|x| x.to_owned())
.filter(|x| x != "")
.collect();
let migrations = lines
.iter()
.map(|x| x.split(" -> ").collect::<Vec<&str>>()[0].into())
.collect::<Vec<_>>();
Ok(migrations)
}