Skip to content

Commit

Permalink
feat: continue work on creating completions table in the shell's data…
Browse files Browse the repository at this point in the history
…base

FossilOrigin-Name: 6afc2cbaa6553a90846be8c3669faef36337130f310d35c454edfc7c2dd1a274
  • Loading branch information
thindil committed Nov 14, 2023
1 parent ce3888b commit e3ba0b5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import std/[os, strutils]
import contracts
import norm/sqlite
# Internal imports
import aliases, directorypath, help, history, logger, lstring, options, output,
plugins, resultcode, variables
import aliases, completion, directorypath, help, history, logger, lstring, options, output, plugins, resultcode, variables

proc closeDb*(returnCode: ResultCode; db: DbConn) {.sideEffect, raises: [],
tags: [DbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect, RootEffect],
Expand Down Expand Up @@ -80,9 +79,9 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
showError(message = "Can't open the shell's database. Reason: ",
e = getCurrentException())
return nil
let options: array[10, Option] = [newOption(name = "dbVersion", value = "4",
let options: array[10, Option] = [newOption(name = "dbVersion", value = "5",
description = "Version of the database schema (read only).",
valueType = ValueType.natural, readOnly = true, defaultValue = "4"),
valueType = ValueType.natural, readOnly = true, defaultValue = "5"),
newOption(name = "promptCommand", value = "built-in",
description = "The command which output will be used as the prompt of shell.",
valueType = ValueType.command, readOnly = false,
Expand Down Expand Up @@ -125,6 +124,8 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
return nil
if result.createHelpDb == QuitFailure:
return nil
if result.createCompletionDb == QuitFailure:
return nil
try:
for option in options:
setOption(optionName = initLimitedString(capacity = 40,
Expand Down Expand Up @@ -155,6 +156,8 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
return nil
if result.createHelpDb == QuitFailure:
return nil
if result.createCompletionDb == QuitFailure:
return nil
for option in options:
setOption(optionName = initLimitedString(capacity = 40,
text = option.option), value = initLimitedString(capacity = 40,
Expand All @@ -167,6 +170,8 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
return nil
if result.updateHistoryDb(dbVersion = dbVersion) == QuitFailure:
return nil
if result.createCompletionDb == QuitFailure:
return nil
for i in options.low..options.high:
if i == 1:
continue
Expand All @@ -184,6 +189,8 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
return nil
if result.updateHistoryDb(dbVersion = dbVersion) == QuitFailure:
return nil
if result.createCompletionDb == QuitFailure:
return nil
setOption(optionName = initLimitedString(capacity = 40,
text = options[0].option), value = initLimitedString(capacity = 40,
text = options[0].value), description = initLimitedString(
Expand All @@ -203,6 +210,9 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
valueType = options[9].valueType, db = result, readOnly = (
if options[9].readOnly: 1 else: 0))
of 4:
if result.createCompletionDb == QuitFailure:
return nil
of 5:
discard
else:
showError(message = "Invalid version of database.")
Expand Down

0 comments on commit e3ba0b5

Please sign in to comment.