Skip to content

Commit

Permalink
refactor: changed setOption description parameter to string and updat…
Browse files Browse the repository at this point in the history
…ed code to the new version of the procedure

FossilOrigin-Name: ebec4abb27415f384c39bbc5a3a538a029ce0ae4701169663c750318a34f7c3a
  • Loading branch information
thindil committed Jan 17, 2024
1 parent 4cda3fb commit ea79c94
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
return nil
try:
for option in options:
setOption(optionName = option.option, value = option.value, description = initLimitedString(
capacity = 256, text = option.description),
setOption(optionName = option.option, value = option.value, description = option.description,
valueType = option.valueType, db = result, readOnly = (
if option.readOnly: 1 else: 0))
except CapacityError:
Expand Down Expand Up @@ -179,8 +178,7 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
if result.createThemeDb == QuitFailure:
return nil
for option in options:
setOption(optionName = option.option, value = option.value, description = initLimitedString(
capacity = 256, text = option.description),
setOption(optionName = option.option, value = option.value, description = option.description,
valueType = option.valueType, db = result, readOnly = (
if option.readOnly: 1 else: 0))
of 2:
Expand All @@ -197,8 +195,7 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
for i in options.low..options.high:
if i == 1:
continue
setOption(optionName = options[i].option, value = options[i].value, description = initLimitedString(
capacity = 256, text = options[i].description),
setOption(optionName = options[i].option, value = options[i].value, description = options[i].description,
valueType = options[i].valueType, db = result, readOnly = (
if options[i].readOnly: 1 else: 0))
of 3:
Expand All @@ -215,16 +212,14 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
if result.createThemeDb == QuitFailure:
return nil
for i in [0, 8, 9, 10, 11]:
setOption(optionName = options[i].option, value = options[i].value, description = initLimitedString(
capacity = 256, text = options[i].description),
setOption(optionName = options[i].option, value = options[i].value, description = options[i].description,
valueType = options[i].valueType, db = result, readOnly = (
if options[i].readOnly: 1 else: 0))
of 4:
if result.createCompletionDb == QuitFailure:
return nil
for i in [0, 10, 11]:
setOption(optionName = options[i].option, value = options[i].value, description = initLimitedString(
capacity = 256, text = options[i].description),
setOption(optionName = options[i].option, value = options[i].value, description = options[i].description,
valueType = options[i].valueType, db = result, readOnly = (
if options[i].readOnly: 1 else: 0))
of 5:
Expand All @@ -233,8 +228,7 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
if result.createThemeDb == QuitFailure:
return nil
for i in [0, 11]:
setOption(optionName = options[i].option, value = options[i].value, description = initLimitedString(
capacity = 256, text = options[i].description),
setOption(optionName = options[i].option, value = options[i].value, description = options[i].description,
valueType = options[i].valueType, db = result, readOnly = (
if options[i].readOnly: 1 else: 0))
of 6:
Expand Down
2 changes: 1 addition & 1 deletion src/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ proc newOption*(name: string = ""; value: string = ""; description: string = "";
valueType: valueType, defaultValue: defaultValue, readOnly: readOnly)

proc setOption*(optionName; value: OptionValue = "";
description: UserInput = emptyLimitedString(capacity = maxInputLength); valueType: OptionValType = none; db;
description: string = ""; valueType: OptionValType = none; db;
readOnly: BooleanInt = 0) {.sideEffect, raises: [], tags: [ReadDbEffect,
WriteDbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect, RootEffect],
contractual.} =
Expand Down
3 changes: 1 addition & 2 deletions src/plugins.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ proc execPlugin*(pluginPath: string; arguments: openArray[string]; db;
return false
try:
setOption(optionName = options[0], value = options[1],
description = initLimitedString(capacity = maxInputLength,
text = options[2]), valueType = parseEnum[OptionValType](
description = options[2], valueType = parseEnum[OptionValType](
s = options[3]), db = db)
except CapacityError, ValueError:
showError(message = "Can't set option '" & options[0] &
Expand Down

0 comments on commit ea79c94

Please sign in to comment.