Test source-preserving writeback for nested authoring
This commit is contained in:
@@ -4,23 +4,43 @@ use std::{collections::BTreeMap, env, fs, process::ExitCode};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<_> = env::args().skip(1).collect();
|
||||
if args.len() != 1 {
|
||||
let rename = args.len() == 4 && args[0] == "--rename";
|
||||
if args.len() != 1 && !rename {
|
||||
eprintln!(
|
||||
"Usage: source-authoring-experiment B_SOURCE_FILE\nIncludes require the library's explicit SourceBundle API."
|
||||
"Usage: source-authoring-experiment B_SOURCE_FILE\n source-authoring-experiment --rename B_SOURCE_FILE ALIAS NAME\nIncludes require the library's explicit SourceBundle API."
|
||||
);
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
let result = fs::read_to_string(&args[0])
|
||||
let result = fs::read_to_string(&args[usize::from(rename)])
|
||||
.map_err(|error| error.to_string())
|
||||
.and_then(|text| {
|
||||
source_authoring_experiment::compile(&SourceBundle {
|
||||
let bundle = SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), text)]),
|
||||
})
|
||||
};
|
||||
let project = source_authoring_experiment::compile(&bundle)?;
|
||||
if rename {
|
||||
let id = project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, alias)| *alias == args[2])
|
||||
.map(|(id, _)| id)
|
||||
.ok_or("Unknown declaration alias")?;
|
||||
let candidate = oa_core::execute_batch(
|
||||
&project,
|
||||
&[oa_core::Command::Rename(id, args[3].clone())],
|
||||
)
|
||||
.map_err(|error| error.to_string())?;
|
||||
let result =
|
||||
source_authoring_experiment::writeback::writeback(&bundle, &candidate)?;
|
||||
Ok(result.files[&result.entry].clone())
|
||||
} else {
|
||||
Ok(language::format(&project))
|
||||
}
|
||||
});
|
||||
match result {
|
||||
Ok(project) => {
|
||||
print!("{}", language::format(&project));
|
||||
Ok(text) => {
|
||||
print!("{text}");
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Err(error) => {
|
||||
|
||||
Reference in New Issue
Block a user