Skip to content

os.cmdline #

os.cmdline

split(text)! separates a command string into shell-like words. Single and double quotes group text; adjacent quoted and unquoted parts form one word. An empty quoted string produces an empty word. Outside quotes, backslash escapes the next byte, and backslash followed by newline continues the current word. Within double quotes, backslash escapes dollar, backtick, double quote, backslash, or newline; other backslashes remain literal. Single-quoted text is literal.

Unbalanced quotes and a trailing unquoted backslash return errors. Whitespace separates words. The function does not expand variables, execute substitutions, or interpret # comments. It only tokenizes input; callers decide how to execute the resulting words.

fn only_non_options #

fn only_non_options(args []string) []string

Fetch all options not start with '-', e.g. args: ['-d', 'aa', '--help', 'bb'] ret: ['aa', 'bb']

fn only_options #

fn only_options(args []string) []string

Fetch all options start with '-', e.g. args: ['-d', 'aa', '--help', 'bb'] ret: ['-d', '--help']

fn option #

fn option(args []string, param string, def string) string

Fetch option by param, e.g. args: ['v', '-d', 'aa'] param: '-d' def: '' ret: 'aa'

fn options #

fn options(args []string, param string) []string

Fetch multiple option by param, e.g. args: ['v', '-d', 'aa', '-d', 'bb', '-d', 'cc'] param: '-d' ret: ['aa', 'bb', 'cc']

fn options_after #

fn options_after(args []string, what []string) []string

Fetch all options after what params, e.g. args: ['-stat', 'test', 'aaa.v'] what: ['test'] ret: ['aaa.v']

fn options_before #

fn options_before(args []string, what []string) []string

Fetch all options before what params, e.g. args: ['-stat', 'test', 'aaa.v'] what: ['test'] ret: ['-stat']

fn split #

fn split(s string) ![]string

split breaks s into shell-like words, e.g. s: 'v run "my prog.v" --flag=value' ret: ['v', 'run', 'my prog.v', '--flag=value'] Single and double quotes group, backslash escapes the next character (newline continues the line), and blank input yields no words. An empty quoted string yields one empty word. # comments are deliberately unsupported (shells disagree on them outside interactive use). Unbalanced quotes and a trailing backslash are errors. It is the V-idiomatic equivalent of Python's shlex.split, and the companion to os.Command / os.execute.