Start working on launcher mode

This commit is contained in:
2021-08-14 13:15:07 +02:00
parent 354ba05faa
commit 9cad6fc050
3 changed files with 36 additions and 7 deletions

View File

@@ -4,11 +4,11 @@ import os
type Args* = object
name*: Option[string]
cmd*: Option[string]
cmd*: Option[seq[string]]
profile*: Option[string]
proc getCmd*(args: Args): string =
return args.cmd.get(getEnv("SHELL", "/bin/bash"))
proc getCmd*(args: Args): seq[string] =
return args.cmd.get(@[getEnv("SHELL", "/bin/bash")])
proc getProfile*(args: Args): string =
if args.profile.isSome:
@@ -18,8 +18,8 @@ proc getProfile*(args: Args): string =
proc parseOpt(args: var Args, key: string, value: string): bool =
case key
of "command", "c":
args.cmd = some(value)
of "name", "n":
args.name = some(value)
of "profile", "p":
args.profile = some(value)
else:
@@ -30,6 +30,7 @@ proc parseOpt(args: var Args, key: string, value: string): bool =
proc parseArgs*(): Option[Args] =
var p = initOptParser()
var args = Args()
var command = newSeq[string]()
while true:
p.next()
@@ -40,6 +41,9 @@ proc parseArgs*(): Option[Args] =
echo "Invalid argument ", p.val
return
of cmdArgument:
args.name = some(p.key.string)
command.add(p.key.string)
if command.len > 0:
args.cmd = some(command)
return some(args)