Skip to content

Commit

Permalink
Allow passing different develop file for all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
yyoncho authored and zah committed Jul 25, 2023
1 parent 2b76173 commit 412af02
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ proc develop(options: var Options) =
hasPackages = options.action.packages.len > 0
hasPath = options.action.path.len > 0
hasDevActions = options.action.devActions.len > 0
hasDevFile = options.action.developFile.len > 0
hasDevFile = options.developFile.len > 0
withDependencies = options.action.withDependencies

var
Expand Down Expand Up @@ -1427,12 +1427,12 @@ proc develop(options: var Options) =
displayDetails(error)

if currentDirPkgInfo.isLoaded and not hasDevFile:
options.action.developFile = developFileName
options.developFile = developFileName

if options.action.developFile.len > 0:
if options.developFile.len > 0:
hasError = not updateDevelopFile(currentDirPkgInfo, options) or hasError
if currentDirPkgInfo.isLoaded and
options.action.developFile == developFileName:
options.developFile == developFileName:
# If we are updated package's develop file we have to update also
# sync and paths files.
updateSyncFile(currentDirPkgInfo, options)
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/developfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ proc updateDevelopFile*(dependentPkg: PackageInfo, options: Options): bool =

options.assertDevelopActionIsSet

let developFile = options.action.developFile
let developFile = options.developFile

var
hasError = false
Expand Down
24 changes: 12 additions & 12 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type
disableLockFile*: bool
enableTarballs*: bool # Enable downloading of packages as tarballs from GitHub.
task*: string # Name of the task that is getting ran
## Whether to put in develop mode also the dependencies of the packages
## listed in the develop command.
developFile*: string
package*: string
# For which package in the dependency tree the command should be executed.
# If not provided by default it applies to the current directory package.
Expand All @@ -68,22 +71,19 @@ type
Action* = object
case typ*: ActionType
of actionNil, actionList, actionPublish, actionTasks, actionCheck,
actionLock, actionSetup, actionClean: nil
actionSetup, actionClean: nil
of actionSync:
listOnly*: bool
of actionRefresh:
optionalURL*: string # Overrides default package list.
of actionInstall, actionPath, actionUninstall, actionDevelop, actionUpgrade:
of actionInstall, actionPath, actionUninstall, actionDevelop, actionUpgrade, actionLock:
packages*: seq[PkgTuple] # Optional only for actionInstall
# and actionDevelop.
passNimFlags*: seq[string]
devActions*: seq[DevelopAction]
path*: string
noRebuild*: bool
withDependencies*: bool
## Whether to put in develop mode also the dependencies of the packages
## listed in the develop command.
developFile*: string
global*: bool
of actionSearch:
search*: seq[string] # Search string.
Expand Down Expand Up @@ -126,8 +126,6 @@ Commands:
[--withDependencies] Puts in develop mode also the dependencies
of the packages in the list or of the current
directory package if the list is empty.
[--developFile] Specifies the name of the develop file which
to be manipulated. If not present creates it.
[-p, --path path] Specifies the path whether the packages should
be cloned.
[-a, --add path] Adds a package at given path to a specified
Expand Down Expand Up @@ -239,6 +237,8 @@ Nimble Options:
--noSslCheck Don't check SSL certificates.
--lockFile Override the lock file name.
--noLockfile Ignore the lock file if present.
--developFile Specifies the name of the develop file which
to be manipulated. If not present creates it.
--useSystemNim Use system nim and ignore nim from the lock
file if any
Expand Down Expand Up @@ -537,6 +537,11 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
of "package", "p": result.package = val
of "lockfile": result.lockFileName = val
of "usesystemnim": result.useSystemNim = true
of "developfile":
if result.developFile.len == 0:
result.developFile = val.normalizedPath
else:
raise nimbleError(multipleDevelopFileOptionsGivenMsg)
else: isGlobalFlag = false

var wasFlagHandled = true
Expand Down Expand Up @@ -617,11 +622,6 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
result.action.withDependencies = true
of "g", "global":
result.action.global = true
of "developfile":
if result.action.developFile.len == 0:
result.action.developFile = val.normalizedPath
else:
raise nimbleError(multipleDevelopFileOptionsGivenMsg)
else:
wasFlagHandled = false
of actionSync:
Expand Down
13 changes: 13 additions & 0 deletions tests/tlockfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,16 @@ requires "nim >= 1.5.1"
let res = execNimbleYes("upgrade", fmt "{dep1PkgName}@#HEAD")
check res.exitCode == QuitSuccess
check defaultLockFileName.readFile.parseJson{$lfjkPackages}.keys.toSeq == @["dep1"]

test "can lock with --developFile argument":
cleanUp()
withPkgListFile:
initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath,
@[dep1PkgName])
initNewNimblePackage(dep1PkgOriginRepoPath, dep1PkgRepoPath)
cd mainPkgRepoPath:
writeDevelopFile(developFileName, @[], @[dep1PkgRepoPath])
moveFile("nimble.develop", "other-name.develop")

let exitCode = execNimbleYes("lock", "--developFile=" & "other-name.develop").exitCode
check exitCode == QuitSuccess

0 comments on commit 412af02

Please sign in to comment.