Skip to content

Commit

Permalink
chore: fixed some issues reported by nimalyzer
Browse files Browse the repository at this point in the history
FossilOrigin-Name: ae52daa9c190f6944af89606c79ecf7aaaf8305d9b693810da02915ec08eeb38
  • Loading branch information
thindil committed Oct 24, 2024
1 parent a61596e commit 3797bab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
23 changes: 16 additions & 7 deletions src/history.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ type
## * lastUsed - the time when the command was recently excute
## * amount - how many times the user executed the command
## * path - the full path in which the command was executed
command*: string
command: CommandName
lastUsed: DateTime
amount: int
amount: int32
path: Path

proc command*(entry: HistoryEntry): CommandName {.sideEffect, raises: [], tags: [],
contractual.} =
## The getter of a field of HistoryEntry type
##
## * entry - the HistoryEntry object which field will be get
##
## Returns the value of the selected field
entry.command

using
db: DbConn # Connection to the shell's database
arguments: UserInput # The arguments for a command entered by the user
Expand All @@ -78,7 +87,7 @@ proc historyLength*(db): HistoryRange {.sideEffect, raises: [], tags: [
return HistoryRange.low

proc newHistoryEntry(command: CommandName = ""; lastUsed: DateTime = now();
amount: Positive = 1; path: Path = "".Path): HistoryEntry {.raises: [],
amount: int32 = 1; path: Path = "".Path): HistoryEntry {.raises: [],
tags: [], contractual.} =
## Create a new data structure for the shell's commands' history entry.
##
Expand Down Expand Up @@ -182,7 +191,7 @@ proc getHistory*(historyIndex: HistoryRange; db;
body:
try:
type LocalEntry = ref object
command: string
command: CommandName
var entry: LocalEntry = LocalEntry()
# Get the command based on the historyIndex parameter
if searchFor.len == 0:
Expand Down Expand Up @@ -294,9 +303,9 @@ proc showHistory(db; arguments): ResultCode {.sideEffect, raises: [],
e = getCurrentException(), db = db)
try:
type LocalEntry = ref object
command: string
command: CommandName
lastUsed: DateTime
amount: int
amount: int32
var entries: seq[LocalEntry] = @[LocalEntry()]
db.rawSelect(qry = "SELECT command, lastused, amount FROM history ORDER BY " &
historyOrder & " LIMIT 0, ?", objs = entries, params = amount)
Expand Down Expand Up @@ -347,7 +356,7 @@ proc findInHistory(db; arguments): ResultCode {.raises: [], tags: [
db = db)).parseInt
var currentRow: Natural = 0
type LocalEntry = ref object
command: string
command: CommandName
var entries: seq[LocalEntry] = @[LocalEntry()]
db.rawSelect(qry = "SELECT command FROM history WHERE command LIKE ? ORDER BY lastused DESC, amount DESC",
objs = entries, params = "%" & searchFor & "%")
Expand Down
8 changes: 3 additions & 5 deletions src/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ type
dirs = "Directories only", files = "Files only",
dirsfiles = "Directories and files", commands = "Commands",
custom = "Custom", none = "Completion for the selected command should be disabled"
CompletionCommand* = string
## Used to store the command to which completion will be added
CompletionValues* = string
## Used to store the values of the selected completion
CommandName* = string
## Used to store the name of a command
Completion* {.tableName: "completions".} = ref object of Model
## Data structure for the shell's commands' completion
##
## * command - the command for which the completion is set
## * cType - the type of completion for the command
## * values - the proper values of completion if the completion's type is
## set to the custom type
command* {.unique.}: CompletionCommand
command* {.unique.}: CommandName
cType*: CompletionType
cValues*: CompletionValues
Plugin* {.tableName: "plugins".} = ref object of Model
Expand Down Expand Up @@ -174,8 +174,6 @@ type
description*: VariableDescription
ResultCode* = distinct Natural
## Used to store result code from commands entered by the user
CommandName* = string
## Used to store the name of the user's command
DbString* = string
## Used to store some text related to database
OutputMessage* = string
Expand Down

0 comments on commit 3797bab

Please sign in to comment.