mirror of
https://github.com/gechandesu/runcmd.git
synced 2026-01-23 14:54:13 +03:00
feat: contexts support
This commit is contained in:
15
runcmd.v
15
runcmd.v
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user