module

Krikri::Shell

Class methods

quote_arg(str : String) : String

One argv element: like quote_if_needed, but whitespace is NOT a safe character here - a value that Ansible hands to run_command as a single argv element (an executable, an image reference, a path, a package name) must never word-split into extra arguments. Well-formed tokens stay byte-identical; an empty value becomes '' so it survives as its own (empty) argument.

Source
quote_if_needed(str : String) : String

Like single_quote, but leaves already-shell-safe tokens (bare words, IPs/CIDRs, port lists, multi-word values such as iptables' set_counters "10 20") untouched, so command strings built from well-formed input stay byte-identical to their unquoted form. Anything containing a shell metacharacter (including an embedded apostrophe) is single-quoted with the correct '\'' escape, so a task param can never terminate the quoting and append commands.

Source
shlex_split(s : String) : Array(String)

Python shlex.split in posix mode, the way Ansible modules turn a multi-argument string param (e.g. podman_image's pull_extra_args) into argv elements: whitespace-separated tokens, single-quoted runs literal, double-quoted runs honoring backslash escapes for \ " ` $ and newline, backslash outside quotes escaping the next character. Each returned token is one argv element, ready to be shell-quoted individually for embedding in a command string.

Source
single_quote(str : String) : String

Single-quotes str for shell embedding, escaping any embedded single quote (POSIX '\'' convention). Safe for arbitrary user data - task param values included, not just our own base64 framing - since nothing inside single quotes is ever reinterpreted.

Source