Skip to content

Commit

Permalink
refactor: small code refactoring
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 156cfd1ffb6e11c39392c5285fda9fe92dc98e74757bf757a31cd3169a24eeec
  • Loading branch information
thindil committed Jan 22, 2024
1 parent 5809296 commit 15f6f70
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/aliases.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ using
aliases: ref AliasesList # The list of aliases available in the selected directory
arguments: UserInput # The string with arguments entered by the user for the command

proc setAliases*(aliases; directory: DirectoryPath; db) {.sideEffect, raises: [],
tags: [ReadDbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect, RootEffect],
proc setAliases*(aliases; directory: DirectoryPath; db) {.sideEffect, raises: [
], tags: [ReadDbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect,
RootEffect],
contractual.} =
## Set the available aliases in the selected directory
##
Expand All @@ -67,7 +68,6 @@ proc setAliases*(aliases; directory: DirectoryPath; db) {.sideEffect, raises: []
directory & "'"
remainingDirectory: DirectoryPath = parentDir(
path = $directory).DirectoryPath

# Construct SQL querry, search for aliases also defined in parent directories
# if they are recursive
while remainingDirectory.len > 0:
Expand All @@ -82,9 +82,7 @@ proc setAliases*(aliases; directory: DirectoryPath; db) {.sideEffect, raises: []
try:
db.rawSelect(qry = dbQuery, objs = dbAliases)
for dbResult in dbAliases:
let index: string =
dbResult.name
aliases[index] = dbResult.id
aliases[dbResult.name] = dbResult.id
except:
showError(message = "Can't set aliases for the current directory. Reason: ",
e = getCurrentException(), db = db)
Expand Down Expand Up @@ -147,11 +145,11 @@ proc listAliases*(arguments; aliases; db): ResultCode {.sideEffect, raises: [],
showOutput(message = "There are no defined shell's aliases in the current directory.", db = db)
return QuitSuccess.ResultCode
try:
let color: string = getColor(db = db, name = ids)
for dbResult in dbAliases:
table.add(parts = [style(ss = dbResult.id, style = getColor(db = db,
name = ids)), style(ss = dbResult.name, style = getColor(db = db,
name = ids)), style(ss = dbResult.description, style = getColor(
db = db, name = default))])
table.add(parts = [style(ss = dbResult.id, style = color), style(
ss = dbResult.name, style = color), style(ss = dbResult.description,
style = getColor(db = db, name = default))])
except:
return showError(message = "Can't add an alias to the list. Reason:",
e = getCurrentException(), db = db)
Expand Down

0 comments on commit 15f6f70

Please sign in to comment.