Skip to content

Commit e824ef7

Browse files
committed
Deprecate --netrc-optional flag
Refactor getNetrcConfig method
1 parent 94db3c5 commit e824ef7

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

Sources/Commands/Options.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ public struct SwiftToolOptions: ParsableArguments {
320320
var netrc: Bool = true
321321

322322
/// Similar to `--netrc`, but this option makes the .netrc usage optional and not mandatory as with the `--netrc` option.
323-
@Flag(name: .customLong("netrc-optional"))
323+
@available(*, deprecated, message: ".netrc files are located by default")
324+
@Flag(name: .customLong("netrc-optional"), help: .hidden)
324325
var netrcOptional: Bool = false
325326

326327
/// The path to the netrc file which should be use for authentication when downloading binary target artifacts.

Sources/Commands/SwiftTool.swift

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -485,27 +485,16 @@ public class SwiftTool {
485485
return try self.getNetrcConfig()?.get()
486486
}
487487

488-
func getNetrcConfig() throws -> Workspace.Configuration.Netrc? {
489-
guard options.netrc || options.netrcFilePath != nil || options.netrcOptional else {
490-
return .none
491-
}
488+
func getNetrcConfig() -> Workspace.Configuration.Netrc? {
489+
guard options.netrc else { return nil }
492490

493-
let netrcFilePath = try self.netrcFilePath()
494-
return netrcFilePath.map { .init(path: $0, fileSystem: localFileSystem) }
495-
}
496-
497-
private func netrcFilePath() throws -> AbsolutePath? {
498-
let netrcFilePath = options.netrcFilePath ?? localFileSystem.homeDirectory.appending(component: ".netrc")
499-
guard localFileSystem.exists(netrcFilePath) else {
500-
if !options.netrcOptional {
501-
ObservabilitySystem.topScope.emit(error: "Cannot find mandatory .netrc file at \(netrcFilePath). To make .netrc file optional, use --netrc-optional flag.")
502-
throw ExitCode.failure
503-
} else {
504-
ObservabilitySystem.topScope.emit(warning: "Did not find optional .netrc file at \(netrcFilePath).")
505-
return .none
506-
}
491+
let path = options.netrcFilePath ?? localFileSystem.homeDirectory.appending(component: ".netrc")
492+
guard localFileSystem.exists(path) else {
493+
ObservabilitySystem.topScope.emit(warning: "Did not find .netrc file at \(path).")
494+
return nil
507495
}
508-
return netrcFilePath
496+
497+
return .init(path: path, fileSystem: localFileSystem)
509498
}
510499

511500
private func getSharedCacheDirectory() throws -> AbsolutePath? {

0 commit comments

Comments
 (0)