| 1 | // vtest vflags: -prod |
| 2 | import os |
| 3 | |
| 4 | struct Process { |
| 5 | path string |
| 6 | argv []string |
| 7 | dir string |
| 8 | } |
| 9 | |
| 10 | struct Command { |
| 11 | path string |
| 12 | args []string |
| 13 | dir string |
| 14 | mut: |
| 15 | process &Process = unsafe { nil } |
| 16 | } |
| 17 | |
| 18 | fn lookup(cmd string) !string { |
| 19 | return os.find_abs_path_of_executable(cmd)! |
| 20 | } |
| 21 | |
| 22 | fn build(mut c Command) ! { |
| 23 | if !isnil(c.process) { |
| 24 | return error('reuse') |
| 25 | } |
| 26 | c.process = &Process{ |
| 27 | path: lookup(c.path)! |
| 28 | argv: c.args |
| 29 | dir: c.dir |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn main() { |
| 34 | mut cmd := Command{ |
| 35 | path: 'bash' |
| 36 | args: ['-c', 'echo ok'] |
| 37 | } |
| 38 | build(mut cmd) or { panic(err) } |
| 39 | } |
| 40 |