33 lines
826 B
Nim
33 lines
826 B
Nim
|
|
import
|
|
std/typetraits, preserves
|
|
|
|
type
|
|
CommandLineKind* {.pure.} = enum
|
|
`shell`, `full`
|
|
CommandLineShell* = string
|
|
`CommandLine`* {.preservesOr.} = object
|
|
case orKind*: CommandLineKind
|
|
of CommandLineKind.`shell`:
|
|
`shell`*: CommandLineShell
|
|
|
|
of CommandLineKind.`full`:
|
|
`full`*: FullCommandLine
|
|
|
|
|
|
Exec* {.preservesRecord: "exec".} = object
|
|
`argv`*: CommandLine
|
|
`restartPolicy`*: RestartPolicy
|
|
|
|
`RestartPolicy`* {.preservesOr, pure.} = enum
|
|
`always`, `onError`, `all`, `never`
|
|
FullCommandLine* {.preservesTuple.} = object
|
|
`program`*: string
|
|
`args`* {.preservesTupleTail.}: seq[string]
|
|
|
|
proc `$`*(x: CommandLine | Exec | FullCommandLine): string =
|
|
`$`(toPreserve(x))
|
|
|
|
proc encode*(x: CommandLine | Exec | FullCommandLine): seq[byte] =
|
|
encode(toPreserve(x))
|