mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
feat: Added --color flag.
This commit is contained in:
19
cli.odin
19
cli.odin
@@ -22,6 +22,7 @@ Flags :: struct {
|
||||
help: bool `args:"short=h"`,
|
||||
config_file: string `args:"name=config-file,short=c"`,
|
||||
output: Output_Format `args:"short=o"`,
|
||||
color: Color_Mode,
|
||||
force: bool `args:"short=f"`,
|
||||
}
|
||||
|
||||
@@ -31,6 +32,12 @@ Output_Format :: enum {
|
||||
JSON,
|
||||
}
|
||||
|
||||
Color_Mode :: enum {
|
||||
Auto,
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
|
||||
CommandInfo :: struct {
|
||||
name: string,
|
||||
usage: string,
|
||||
@@ -95,6 +102,13 @@ parse_args :: proc(args: []string, out: io.Stream, err: io.Stream) -> (cmd: Comm
|
||||
cmd.flags.output = terminal.is_terminal(os.stdout) ? .Table : .JSON
|
||||
}
|
||||
|
||||
if cmd.flags.color == .Auto {
|
||||
cmd.flags.color = terminal.is_terminal(os.stdout) ? .Always : .Never
|
||||
}
|
||||
if cmd.flags.color == .Never {
|
||||
cmd.out = make_ansi_strip_writer(cmd.out)
|
||||
}
|
||||
|
||||
if cmd.flags.config_file == "" {
|
||||
// FIXME: Handle err
|
||||
// TODO: Is this right?
|
||||
@@ -279,6 +293,11 @@ at before, restore your backup with:
|
||||
COLOR_FLAGS + "-o, --output" + ANSI_RESET + " 'table'|'json'",
|
||||
`the format of output data. (default 'table')`,
|
||||
)
|
||||
table.row(
|
||||
&tbl,
|
||||
COLOR_FLAGS + "--color" + ANSI_RESET + " 'auto'|'always'|'never'",
|
||||
`Whether or not to colorize output. (default 'auto')`,
|
||||
)
|
||||
write_borderless_table(w, &tbl)
|
||||
|
||||
fmt.wprintf(
|
||||
|
||||
Reference in New Issue
Block a user