feat: contexts support

This commit is contained in:
ge
2026-01-03 19:17:50 +03:00
parent b790cfef0a
commit 055dab663e
5 changed files with 176 additions and 9 deletions

View File

@@ -1,8 +1,9 @@
module runcmd
import context
import os
// new creates new Command instance with given command name and arguments.
// new creates new command with given command name and arguments.
pub fn new(name string, arg ...string) &Command {
return &Command{
path: name
@@ -10,6 +11,18 @@ pub fn new(name string, arg ...string) &Command {
}
}
// with_context creates new command with context, command name and arguments.
pub fn with_context(ctx context.Context, name string, arg ...string) &Command {
mut cmd := new(name, ...arg)
cmd.ctx = ctx
cmd.cancel = fn [mut cmd] () ! {
if cmd.process != none {
cmd.process.signal(.term)!
}
}
return cmd
}
// is_present returns true if cmd is present on system. cmd may be a command
// name or filepath (relative or absolute).
// The result relies on `look_path()` output, see its docs for command search