Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add override print args in the exec function. #179

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kclvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn kclvm_cli_run_unsafe(args: *const i8, plugin_agent: *const i8) -> Result<

// Parse AST program.
let mut program = load_program(&files, Some(opts))?;
if let Err(msg) = apply_overrides(&mut program, &args.overrides, &[]) {
if let Err(msg) = apply_overrides(&mut program, &args.overrides, &[], args.print_override_ast) {
return Err(msg.to_string());
}

Expand Down
5 changes: 3 additions & 2 deletions kclvm/tools/src/query/override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ const IMPORT_STMT_COLUMN_OFFSET: u64 = 1;
/// let mut prog = load_program(&["config.k"], None).unwrap();
/// let overrides = vec![parse_override_spec("config.id=1").unwrap()];
/// let import_paths = vec!["path.to.pkg".to_string()];
/// let result = apply_overrides(&mut prog, &overrides, &import_paths).unwrap();
/// let result = apply_overrides(&mut prog, &overrides, &import_paths, true).unwrap();
/// ```
pub fn apply_overrides(
prog: &mut ast::Program,
overrides: &[ast::OverrideSpec],
import_paths: &[String],
print_ast: bool,
) -> Result<()> {
for o in overrides {
let pkgpath = if o.pkgpath.is_empty() {
Expand All @@ -47,7 +48,7 @@ pub fn apply_overrides(
};
if let Some(modules) = prog.pkgs.get_mut(pkgpath) {
for m in modules.iter_mut() {
if apply_override_on_module(m, o, import_paths)? {
if apply_override_on_module(m, o, import_paths)? && print_ast {
let code_str = print_ast_module(m);
std::fs::write(&m.filename, &code_str)?
}
Expand Down