Skip to content

Commit 3797bab

Browse files
committed
chore: fixed some issues reported by nimalyzer
FossilOrigin-Name: ae52daa9c190f6944af89606c79ecf7aaaf8305d9b693810da02915ec08eeb38
1 parent a61596e commit 3797bab

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/history.nim

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ type
4949
## * lastUsed - the time when the command was recently excute
5050
## * amount - how many times the user executed the command
5151
## * path - the full path in which the command was executed
52-
command*: string
52+
command: CommandName
5353
lastUsed: DateTime
54-
amount: int
54+
amount: int32
5555
path: Path
5656

57+
proc command*(entry: HistoryEntry): CommandName {.sideEffect, raises: [], tags: [],
58+
contractual.} =
59+
## The getter of a field of HistoryEntry type
60+
##
61+
## * entry - the HistoryEntry object which field will be get
62+
##
63+
## Returns the value of the selected field
64+
entry.command
65+
5766
using
5867
db: DbConn # Connection to the shell's database
5968
arguments: UserInput # The arguments for a command entered by the user
@@ -78,7 +87,7 @@ proc historyLength*(db): HistoryRange {.sideEffect, raises: [], tags: [
7887
return HistoryRange.low
7988

8089
proc newHistoryEntry(command: CommandName = ""; lastUsed: DateTime = now();
81-
amount: Positive = 1; path: Path = "".Path): HistoryEntry {.raises: [],
90+
amount: int32 = 1; path: Path = "".Path): HistoryEntry {.raises: [],
8291
tags: [], contractual.} =
8392
## Create a new data structure for the shell's commands' history entry.
8493
##
@@ -182,7 +191,7 @@ proc getHistory*(historyIndex: HistoryRange; db;
182191
body:
183192
try:
184193
type LocalEntry = ref object
185-
command: string
194+
command: CommandName
186195
var entry: LocalEntry = LocalEntry()
187196
# Get the command based on the historyIndex parameter
188197
if searchFor.len == 0:
@@ -294,9 +303,9 @@ proc showHistory(db; arguments): ResultCode {.sideEffect, raises: [],
294303
e = getCurrentException(), db = db)
295304
try:
296305
type LocalEntry = ref object
297-
command: string
306+
command: CommandName
298307
lastUsed: DateTime
299-
amount: int
308+
amount: int32
300309
var entries: seq[LocalEntry] = @[LocalEntry()]
301310
db.rawSelect(qry = "SELECT command, lastused, amount FROM history ORDER BY " &
302311
historyOrder & " LIMIT 0, ?", objs = entries, params = amount)
@@ -347,7 +356,7 @@ proc findInHistory(db; arguments): ResultCode {.raises: [], tags: [
347356
db = db)).parseInt
348357
var currentRow: Natural = 0
349358
type LocalEntry = ref object
350-
command: string
359+
command: CommandName
351360
var entries: seq[LocalEntry] = @[LocalEntry()]
352361
db.rawSelect(qry = "SELECT command FROM history WHERE command LIKE ? ORDER BY lastused DESC, amount DESC",
353362
objs = entries, params = "%" & searchFor & "%")

src/types.nim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ type
124124
dirs = "Directories only", files = "Files only",
125125
dirsfiles = "Directories and files", commands = "Commands",
126126
custom = "Custom", none = "Completion for the selected command should be disabled"
127-
CompletionCommand* = string
128-
## Used to store the command to which completion will be added
129127
CompletionValues* = string
130128
## Used to store the values of the selected completion
129+
CommandName* = string
130+
## Used to store the name of a command
131131
Completion* {.tableName: "completions".} = ref object of Model
132132
## Data structure for the shell's commands' completion
133133
##
134134
## * command - the command for which the completion is set
135135
## * cType - the type of completion for the command
136136
## * values - the proper values of completion if the completion's type is
137137
## set to the custom type
138-
command* {.unique.}: CompletionCommand
138+
command* {.unique.}: CommandName
139139
cType*: CompletionType
140140
cValues*: CompletionValues
141141
Plugin* {.tableName: "plugins".} = ref object of Model
@@ -174,8 +174,6 @@ type
174174
description*: VariableDescription
175175
ResultCode* = distinct Natural
176176
## Used to store result code from commands entered by the user
177-
CommandName* = string
178-
## Used to store the name of the user's command
179177
DbString* = string
180178
## Used to store some text related to database
181179
OutputMessage* = string

0 commit comments

Comments
 (0)