mirror of
https://github.com/status-im/nimbus-launch.git
synced 2025-02-27 04:20:42 +00:00
Add cligen for CLI parsing + PoC license inputs
This commit is contained in:
parent
7a07e03435
commit
79876e177b
0
.gitignore.nim → .gitignore
vendored
0
.gitignore.nim → .gitignore
vendored
@ -7,7 +7,7 @@ srcDir = "src"
|
||||
|
||||
### Dependencies
|
||||
|
||||
requires "nim >= 0.18.0"
|
||||
requires "nim >= 0.18.0", "https://github.com/c-blake/cligen#head"
|
||||
|
||||
proc test(name: string, lang: string = "cpp") =
|
||||
if not dirExists "build":
|
||||
|
@ -7,4 +7,37 @@
|
||||
#
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import cligen, argcvt # argcvt is part of cligen
|
||||
import strutils
|
||||
|
||||
type
|
||||
License = enum
|
||||
MIT, Apache2, GPLv2, GPLv3
|
||||
|
||||
Licenses = set[License]
|
||||
|
||||
# Add Licenses support to cligen
|
||||
template argParse(dst: Licenses, key: string, val: string, help: string) =
|
||||
let args = val.split(',')
|
||||
dst = {}
|
||||
for input_license in args:
|
||||
var isValid: bool = false
|
||||
for supported_license in low(License)..high(License): # Interesting read: "parseEnum is slow" https://forum.nim-lang.org/t/2949
|
||||
if cmpIgnoreStyle(input_license, $supported_license) == 0:
|
||||
incl(dst, supported_license)
|
||||
isValid = true
|
||||
if not isValid:
|
||||
argRet(1, "Wrong input license(s) for param \"$1\"\n$2" %
|
||||
[key, help])
|
||||
|
||||
template argHelp(helpT: seq[array[0..3, string]], defVal: Licenses,
|
||||
parNm: string, sh: string, parHelp: string) =
|
||||
helpT.add([ keys(parNm, sh), "Licenses", $defVal, parHelp ])
|
||||
|
||||
proc nimbusLaunch(licenses: Licenses = {MIT, Apache2}): int =
|
||||
echo licenses
|
||||
echo licenses.card # length (cardinality) of the set
|
||||
|
||||
when isMainModule:
|
||||
dispatch nimbusLaunch
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user