@@ -31,6 +31,9 @@ proc refresh(options: Options) =
31
31
# # Downloads the package list from the specified URL.
32
32
# #
33
33
# # 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
+
34
37
let parameter =
35
38
if options.action.typ == actionRefresh:
36
39
options.action.optionalURL
@@ -310,7 +313,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
310
313
PackageDependenciesInfo =
311
314
## Returns where package has been installed to, together with paths
312
315
## to the packages this package depends on .
313
- ##
316
+ ##
314
317
## The return value of this function is used by
315
318
## ``processFreeDependencies``
316
319
## To gather a list of paths to pass to the Nim compiler.
@@ -507,6 +510,8 @@ proc raiseCannotCloneInExistingDirException(downloadDir: string) =
507
510
proc downloadDependency(name: string , dep: LockFileDep, options: Options):
508
511
DownloadInfo =
509
512
## Downloads a dependency from the lock file.
513
+ if options.offline:
514
+ raise nimbleError("Cannot download in offline mode.")
510
515
511
516
if not options.developWithDependencies:
512
517
let depDirName = getDependencyDir(name, dep, options)
@@ -547,14 +552,14 @@ proc downloadDependency(name: string, dep: LockFileDep, options: Options):
547
552
result = DownloadInfo(
548
553
name: name,
549
554
dependency: dep,
550
- url: url,
555
+ url: url,
551
556
version: version,
552
557
downloadDir: downloadDir,
553
558
vcsRevision: vcsRevision)
554
559
555
560
proc installDependency(pkgInfo: PackageInfo, downloadInfo: DownloadInfo,
556
561
options: Options): PackageInfo =
557
- ## Installs an already downloaded dependency of the package `pkgInfo`.
562
+ ## Installs an already downloaded dependency of the package `pkgInfo`.
558
563
let (_, newlyInstalledPkgInfo) = installFromDir(
559
564
downloadInfo.downloadDir,
560
565
downloadInfo.version,
@@ -569,7 +574,7 @@ proc installDependency(pkgInfo: PackageInfo, downloadInfo: DownloadInfo,
569
574
for depDepName in downloadInfo.dependency.dependencies:
570
575
let depDep = pkgInfo.lockedDeps[depDepName]
571
576
let revDep = (name: depDepName, version: depDep.version,
572
- checksum: depDep.checksums.sha1)
577
+ checksum: depDep.checksums.sha1)
573
578
options.nimbleData.addRevDep(revDep, newlyInstalledPkgInfo)
574
579
575
580
return newlyInstalledPkgInfo
@@ -589,9 +594,11 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
589
594
result .incl developModeDeps[name][]
590
595
elif isInstalled(name, dep, options):
591
596
result .incl getDependency(name, dep, options)
592
- else :
597
+ elif not options.offline :
593
598
let downloadResult = downloadDependency(name, dep, options)
594
599
result .incl installDependency(pkgInfo, downloadResult, options)
600
+ else:
601
+ raise nimbleError("Unsatisfied dependency: " & pkgInfo.basicInfo.name)
595
602
596
603
proc getDownloadInfo*(pv: PkgTuple, options: Options,
597
604
doPrompt: bool ): (DownloadMethod, string ,
@@ -607,7 +614,7 @@ proc getDownloadInfo*(pv: PkgTuple, options: Options,
607
614
else:
608
615
# If package is not found give the user a chance to refresh
609
616
# package.json
610
- if doPrompt and
617
+ if doPrompt and not options.offline and
611
618
options.prompt(pv.name & " not found in any local packages.json, " &
612
619
"check internet for updated packages?"):
613
620
refresh(options)
@@ -1466,7 +1473,7 @@ proc validateDevModeDepsWorkingCopiesBeforeLock(
1466
1473
vekWorkingCopyNeedsLock,
1467
1474
vekWorkingCopyNeedsMerge,
1468
1475
}
1469
-
1476
+
1470
1477
# Remove not errors from the errors set.
1471
1478
for name, error in common.dup(errors):
1472
1479
if error.kind in notAnErrorSet:
@@ -1507,7 +1514,7 @@ proc mergeLockedDependencies*(pkgInfo: PackageInfo, newDeps: LockFileDeps,
1507
1514
proc displayLockOperationStart(dir: string ): bool =
1508
1515
# # Displays a proper log message for starting generating or updating the lock
1509
1516
# # file of a package in directory `dir`.
1510
-
1517
+
1511
1518
var doesLockFileExist = dir.lockFileExists
1512
1519
let msg = if doesLockFileExist:
1513
1520
updatingTheLockFileMsg
@@ -1527,7 +1534,7 @@ proc displayLockOperationFinish(didLockFileExist: bool) =
1527
1534
displaySuccess(msg)
1528
1535
1529
1536
proc 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
1531
1538
# # it if it already exists.
1532
1539
1533
1540
let currentDir = getCurrentDir()
@@ -1564,6 +1571,9 @@ proc syncWorkingCopy(name: string, path: Path, dependentPkg: PackageInfo,
1564
1571
# # with name `name` at path `path` with the revision from the lock file of
1565
1572
# # `dependentPkg`.
1566
1573
1574
+ if options.offline:
1575
+ raise nimbleError(" Cannot sync in offline mode." )
1576
+
1567
1577
displayInfo(& " Syncing working copy of package \" { name} \" at \" { path} \" ... " )
1568
1578
1569
1579
let lockedDeps = dependentPkg.lockedDeps
@@ -1594,7 +1604,7 @@ proc syncWorkingCopy(name: string, path: Path, dependentPkg: PackageInfo,
1594
1604
path, vcsRevision, btRemoteTracking)
1595
1605
allBranches = localBranches + remoteTrackingBranches
1596
1606
1597
- var targetBranch =
1607
+ var targetBranch =
1598
1608
if allBranches.len == 0 :
1599
1609
# Te revision is not found on any branch.
1600
1610
" "
@@ -1677,6 +1687,9 @@ proc sync(options: Options) =
1677
1687
if not pkgInfo.areLockedDepsLoaded:
1678
1688
raise nimbleError(" Cannot execute `sync` when lock file is missing." )
1679
1689
1690
+ if options.offline:
1691
+ raise nimbleError(" Cannot execute `sync` in offline mode." )
1692
+
1680
1693
if not options.action.listOnly:
1681
1694
# On `sync` we also want to update Nimble cache with the dependencies'
1682
1695
# versions from the lock file.
0 commit comments