swydd api

Note

Usage examples will follow once API is more stable.

class swydd.Proc(cmd: str, **kwargs: Any)

a class

pipe(proc: str | Proc) ProcPipe

ProcPipe the output into proc

Parameters:

proc – Command to feed stdout into

Return type:

ProcPipe

then(proc: str | Proc | ProcSeq) ProcSeq

If successful execute next proc

Parameters:

proc – Command to execute after

Return type:

ProcSeq

class swydd.ProcPipe(*procs: str | Proc | ProcPipe)

prefer: Proc.pipe()

class swydd.ProcSeq(*procs: str | Proc | ProcSeq)

prefer: Proc.then()

swydd.cli(default: str | None = None) None

activate swydd cli

Parameters:

default – The default args passed line passed on to sywdd.

swydd.get(proc: str | Proc | ProcPipe | ProcSeq, stdout=True, stderr=False) str

execute subprocess and capture outputs

see also: geterr()

Parameters:
  • proc – Command to execute.

  • stdout – If true, capture stdout

  • stderr – If true, capture stderr

Returns:

Captured output

Return type:

str

swydd.geterr(proc: str | Proc | ProcPipe | ProcSeq) str

execute subprocess and return stderr

Parameters:

proc (str, Proc, ProcSeq, ProcPipe) – Command to execute.

Returns:

Output captured from stderr.

Return type:

str

swydd.option(name: str, help: str, short: str = '', **help_kwargs: str) Callable[[Callable[..., Any]], Callable[..., Callable[..., None]]]

add help and additional args for option

Parameters:
  • name – variable name used in wrapped function, subsitute underscores with hypens

  • help – help description for variable

  • **help_kwargs – kwargs which will be passed onto argparse.ArgumentParser.add_argument()

swydd.setenv(key: str, value: str) None

Set environment variable shared by all Procs

swydd.task(arg: Callable[..., Any] | None = None)

decorator to convert a function into a swydd task