mirror of
https://github.com/daylinmorgan/bbansi.git
synced 2024-11-21 17:00:44 -06:00
feat: add additional cli flags
This commit is contained in:
parent
bcc70173b5
commit
9bf3b17a7b
1 changed files with 21 additions and 4 deletions
|
@ -134,6 +134,7 @@ proc `&`*(x: BbString, y: BbString): Bbstring =
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import std/[strformat, parseopt]
|
import std/[strformat, parseopt]
|
||||||
const version = staticExec "git describe --tags --always --dirty=-dev"
|
const version = staticExec "git describe --tags --always --dirty=-dev"
|
||||||
|
const longOptPad = 8
|
||||||
let help = &"""
|
let help = &"""
|
||||||
{bb"[bold]bbansi[/] \[[green]args...[/]] [faint][[-h,-v][/]"}
|
{bb"[bold]bbansi[/] \[[green]args...[/]] [faint][[-h,-v][/]"}
|
||||||
|
|
||||||
|
@ -142,12 +143,16 @@ when isMainModule:
|
||||||
|-> {bb"[yellow] yellow text!"}
|
|-> {bb"[yellow] yellow text!"}
|
||||||
bbansi "[bold red] bold red text[/] plain text..."
|
bbansi "[bold red] bold red text[/] plain text..."
|
||||||
|-> {bb"[bold red] bold red text[/] plain text..."}
|
|-> {bb"[bold red] bold red text[/] plain text..."}
|
||||||
|
bbansi "[red]some red[/red] but all bold" --style:bold
|
||||||
|
|-> {"[red]some red[/red] but all bold".bb("bold")}
|
||||||
|
|
||||||
flags:
|
flags:
|
||||||
""" & $(bb(collect(for (s, l, d) in [
|
""" & $(bb(collect(for (s, l, d) in [
|
||||||
("h", "help", "show this help"),
|
("h", "help", "show this help"),
|
||||||
("v", "version", "show version")]:
|
("v", "version", "show version"),
|
||||||
&"[yellow]-{s}[/] [green]--{l.alignLeft(8)}[/] {d}").join("\n ")
|
("s", "style", "set style for string")
|
||||||
|
]:
|
||||||
|
&"[yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}").join("\n ")
|
||||||
))
|
))
|
||||||
proc writeHelp() =
|
proc writeHelp() =
|
||||||
echo help
|
echo help
|
||||||
|
@ -155,7 +160,10 @@ flags:
|
||||||
proc writeVersion() =
|
proc writeVersion() =
|
||||||
echo bb(&"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]")
|
echo bb(&"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]")
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
var strArgs: seq[string]
|
var
|
||||||
|
strArgs: seq[string]
|
||||||
|
style: string
|
||||||
|
showDebug: bool
|
||||||
var p = initOptParser()
|
var p = initOptParser()
|
||||||
for kind, key, val in p.getopt():
|
for kind, key, val in p.getopt():
|
||||||
case kind:
|
case kind:
|
||||||
|
@ -164,6 +172,8 @@ flags:
|
||||||
case key:
|
case key:
|
||||||
of "help", "h": writeHelp()
|
of "help", "h": writeHelp()
|
||||||
of "version", "v": writeVersion()
|
of "version", "v": writeVersion()
|
||||||
|
of "style", "s": style = val
|
||||||
|
of "debug": showDebug = true
|
||||||
else:
|
else:
|
||||||
echo bb"[red]ERROR[/]: unexpected option/value -> ", key, ", ", val
|
echo bb"[red]ERROR[/]: unexpected option/value -> ", key, ", ", val
|
||||||
echo "Option and value: ", key, ", ", val
|
echo "Option and value: ", key, ", ", val
|
||||||
|
@ -174,4 +184,11 @@ flags:
|
||||||
echo help
|
echo help
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
for arg in strArgs:
|
for arg in strArgs:
|
||||||
echo arg.bb
|
let styled =
|
||||||
|
if style != "":
|
||||||
|
arg.bb(style)
|
||||||
|
else: arg.bb
|
||||||
|
echo styled
|
||||||
|
if showDebug:
|
||||||
|
echo debug(styled)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue