44 lines
1.1 KiB
Odin
44 lines
1.1 KiB
Odin
package comb
|
|
|
|
import "core:log"
|
|
import "core:fmt"
|
|
import "core:strings"
|
|
import "core:flags"
|
|
import "core:os/os2"
|
|
|
|
example_1 :: string(#load("example_1.md"))
|
|
|
|
CLI_Options :: struct {
|
|
file_path: string `args:"pos=0,required" usage:"Input file"`
|
|
}
|
|
|
|
main :: proc() {
|
|
context.logger = log.create_console_logger()
|
|
opt: CLI_Options
|
|
flags.parse_or_exit(&opt, os2.args)
|
|
// TODO: handle error
|
|
data, _ := os2.read_entire_file(opt.file_path, context.allocator)
|
|
defer delete(data)
|
|
content := string(data)
|
|
// TODO: handle error
|
|
blocks, _ := parse_code_blocks(content)
|
|
defer for b in blocks do destroy_code_block(b)
|
|
if len(blocks) == 0 {
|
|
log.info("No code blocks detected.")
|
|
return
|
|
}
|
|
for block, i in blocks {
|
|
log.infof("Executing block #%v (%v), starting on line %v...", i, block.language, block.line_start)
|
|
stdout, stderr, err := eval_code_block(block)
|
|
defer delete(stdout)
|
|
defer delete(stderr)
|
|
if err != nil {
|
|
log.errorf("Failed to execute code block: %v", err)
|
|
return
|
|
}
|
|
|
|
if stdout != "" do log.infof("Stdout: %v", strings.trim_space(stdout))
|
|
if stderr != "" do log.infof("Stderr: %v", strings.trim_space(stderr))
|
|
}
|
|
}
|