bwbox/lib/args.nim

41 lines
792 B
Nim
Raw Permalink Normal View History

2021-06-19 16:33:47 +02:00
import options
import os
type Args* = object
name*: Option[string]
2021-08-14 13:15:07 +02:00
cmd*: Option[seq[string]]
2021-06-19 16:33:47 +02:00
profile*: Option[string]
2021-08-14 13:15:07 +02:00
proc getCmd*(args: Args): seq[string] =
return args.cmd.get(@[getEnv("SHELL", "/bin/bash")])
2021-06-19 16:33:47 +02:00
2021-06-20 14:09:30 +02:00
proc getProfile*(args: Args): string =
2021-06-19 16:33:47 +02:00
if args.profile.isSome:
return args.profile.unsafeGet
2021-06-20 14:09:30 +02:00
return "default"
2021-06-19 16:33:47 +02:00
proc parseArgs*(): Option[Args] =
var args = Args()
var command = newSeq[string]()
var i = 1
while i <= paramCount():
var arg = paramStr(i)
if arg == "--name":
args.name = some(paramStr(i + 1))
i += 2
elif arg == "--profile":
args.profile = some(paramStr(i + 1))
i += 2
else:
echo arg
command.add(arg)
i += 1
2021-08-14 13:15:07 +02:00
if command.len > 0:
args.cmd = some(command)
2021-06-19 16:33:47 +02:00
return some(args)