@@ -31,6 +31,9 @@ proc refresh(options: Options) =
3131 # # Downloads the package list from the specified URL.
3232 # #
3333 # # If the download is not successful, an exception is raised.
34+ if options.offline:
35+ raise nimbleError (" Cannot refresh package list in offline mode." )
36+
3437 let parameter =
3538 if options.action.typ == actionRefresh:
3639 options.action.optionalURL
@@ -310,7 +313,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
310313 PackageDependenciesInfo =
311314 # # Returns where package has been installed to, together with paths
312315 # # to the packages this package depends on.
313- # #
316+ # #
314317 # # The return value of this function is used by
315318 # # ``processFreeDependencies``
316319 # # To gather a list of paths to pass to the Nim compiler.
@@ -507,6 +510,8 @@ proc raiseCannotCloneInExistingDirException(downloadDir: string) =
507510proc downloadDependency (name: string , dep: LockFileDep , options: Options ):
508511 DownloadInfo =
509512 # # Downloads a dependency from the lock file.
513+ if options.offline:
514+ raise nimbleError (" Cannot download in offline mode." )
510515
511516 if not options.developWithDependencies:
512517 let depDirName = getDependencyDir (name, dep, options)
@@ -547,14 +552,14 @@ proc downloadDependency(name: string, dep: LockFileDep, options: Options):
547552 result = DownloadInfo (
548553 name: name,
549554 dependency: dep,
550- url: url,
555+ url: url,
551556 version: version,
552557 downloadDir: downloadDir,
553558 vcsRevision: vcsRevision)
554559
555560proc installDependency (pkgInfo: PackageInfo , downloadInfo: DownloadInfo ,
556561 options: Options ): PackageInfo =
557- # # Installs an already downloaded dependency of the package `pkgInfo`.
562+ # # Installs an already downloaded dependency of the package `pkgInfo`.
558563 let (_, newlyInstalledPkgInfo) = installFromDir (
559564 downloadInfo.downloadDir,
560565 downloadInfo.version,
@@ -569,7 +574,7 @@ proc installDependency(pkgInfo: PackageInfo, downloadInfo: DownloadInfo,
569574 for depDepName in downloadInfo.dependency.dependencies:
570575 let depDep = pkgInfo.lockedDeps[depDepName]
571576 let revDep = (name: depDepName, version: depDep.version,
572- checksum: depDep.checksums.sha1)
577+ checksum: depDep.checksums.sha1)
573578 options.nimbleData.addRevDep (revDep, newlyInstalledPkgInfo)
574579
575580 return newlyInstalledPkgInfo
@@ -589,9 +594,11 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
589594 result .incl developModeDeps[name][]
590595 elif isInstalled (name, dep, options):
591596 result .incl getDependency (name, dep, options)
592- else :
597+ elif not options.offline :
593598 let downloadResult = downloadDependency (name, dep, options)
594599 result .incl installDependency (pkgInfo, downloadResult, options)
600+ else :
601+ raise nimbleError (" Unsatisfied dependency: " & pkgInfo.basicInfo.name)
595602
596603proc getDownloadInfo * (pv: PkgTuple , options: Options ,
597604 doPrompt: bool ): (DownloadMethod , string ,
@@ -607,7 +614,7 @@ proc getDownloadInfo*(pv: PkgTuple, options: Options,
607614 else :
608615 # If package is not found give the user a chance to refresh
609616 # package.json
610- if doPrompt and
617+ if doPrompt and not options.offline and
611618 options.prompt (pv.name & " not found in any local packages.json, " &
612619 " check internet for updated packages?" ):
613620 refresh (options)
@@ -1466,7 +1473,7 @@ proc validateDevModeDepsWorkingCopiesBeforeLock(
14661473 vekWorkingCopyNeedsLock,
14671474 vekWorkingCopyNeedsMerge,
14681475 }
1469-
1476+
14701477 # Remove not errors from the errors set.
14711478 for name, error in common.dup (errors):
14721479 if error.kind in notAnErrorSet:
@@ -1507,7 +1514,7 @@ proc mergeLockedDependencies*(pkgInfo: PackageInfo, newDeps: LockFileDeps,
15071514proc displayLockOperationStart (dir: string ): bool =
15081515 # # Displays a proper log message for starting generating or updating the lock
15091516 # # file of a package in directory `dir`.
1510-
1517+
15111518 var doesLockFileExist = dir.lockFileExists
15121519 let msg = if doesLockFileExist:
15131520 updatingTheLockFileMsg
@@ -1527,7 +1534,7 @@ proc displayLockOperationFinish(didLockFileExist: bool) =
15271534 displaySuccess (msg)
15281535
15291536proc lock (options: Options ) =
1530- # # Generates a lock file for the package in the current directory or updates
1537+ # # Generates a lock file for the package in the current directory or updates
15311538 # # it if it already exists.
15321539
15331540 let currentDir = getCurrentDir ()
@@ -1564,6 +1571,9 @@ proc syncWorkingCopy(name: string, path: Path, dependentPkg: PackageInfo,
15641571 # # with name `name` at path `path` with the revision from the lock file of
15651572 # # `dependentPkg`.
15661573
1574+ if options.offline:
1575+ raise nimbleError (" Cannot sync in offline mode." )
1576+
15671577 displayInfo (& " Syncing working copy of package \" { name} \" at \" { path} \" ... " )
15681578
15691579 let lockedDeps = dependentPkg.lockedDeps
@@ -1594,7 +1604,7 @@ proc syncWorkingCopy(name: string, path: Path, dependentPkg: PackageInfo,
15941604 path, vcsRevision, btRemoteTracking)
15951605 allBranches = localBranches + remoteTrackingBranches
15961606
1597- var targetBranch =
1607+ var targetBranch =
15981608 if allBranches.len == 0 :
15991609 # Te revision is not found on any branch.
16001610 " "
@@ -1677,6 +1687,9 @@ proc sync(options: Options) =
16771687 if not pkgInfo.areLockedDepsLoaded:
16781688 raise nimbleError (" Cannot execute `sync` when lock file is missing." )
16791689
1690+ if options.offline:
1691+ raise nimbleError (" Cannot execute `sync` in offline mode." )
1692+
16801693 if not options.action.listOnly:
16811694 # On `sync` we also want to update Nimble cache with the dependencies'
16821695 # versions from the lock file.
0 commit comments