-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some basic bits needed to operationalize components in Chalk, such as being able to ask for parameters on the command line (see params.nim) and to parse inputs that are expected to be Con4m literals. Note if the expected type is 'string' then we accept their entire input without quotes. Otherwise, we parse the text under the assumption it's a con4m literal.
- Loading branch information
Showing
6 changed files
with
377 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import types, treecheck, options, tables, nimutils, eval, dollars | ||
|
||
|
||
proc basicConfigureOneParam(state: ConfigState, | ||
component: ComponentInfo, | ||
param: ParameterInfo) = | ||
var | ||
boxOpt: Option[Box] | ||
default = "<<no default>>" | ||
|
||
if param.value.isSome(): | ||
boxOpt = param.value | ||
elif param.default.isSome(): | ||
boxOpt = param.default | ||
elif param.defaultCb.isSome(): | ||
boxOpt = state.sCall(param.defaultCb.get(), @[]) | ||
|
||
if boxOpt.isSome(): | ||
default = param.defaultType.oneArgToString(boxOpt.get()) | ||
let | ||
short = param.shortDoc.getOrElse("No description provided") | ||
long = param.doc.getOrElse("") | ||
|
||
print("### Configuring: " & param.name & " -- " & short & "\n" & long) | ||
|
||
if boxOpt.isSome(): | ||
print("Press [enter] to accept default, or enter a value: ") | ||
|
||
while true: | ||
let line = stdin.readLine() | ||
|
||
if line != "": | ||
try: | ||
boxOpt = some(line.parseConstLiteral(param.defaultType)) | ||
except: | ||
print("<red>error:</red> " & getCurrentExceptionMsg()) | ||
|
||
if boxOpt.isNone(): | ||
print("<red>error:</red> Must enter a valid value.") | ||
continue | ||
elif line == "": | ||
print("<atomiclime>success:</atomiclime> Accepting the default value.") | ||
else: | ||
print("<atomiclime>success:</atomiclime> Value accepted.") | ||
|
||
param.value = boxOpt | ||
break | ||
|
||
proc basicConfigureParameters*(state: ConfigState, | ||
component: ComponentInfo, | ||
componentList: seq[ComponentInfo]) = | ||
print("# Congiguring Component: " & component.url) | ||
for subcomp in componentList: | ||
for _, param in subcomp.varParams: | ||
state.basicConfigureOneParam(subcomp, param) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.