From 7c9747399257d9bb7f2075e72bc9003dfa91d47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCllenborn?= Date: Wed, 21 Oct 2020 14:37:12 +0200 Subject: [PATCH] [Windows] use _dupenv_s instead of getenv getenv generates a warning on windows. --- .../ArgumentParser/Completions/CompletionsGenerator.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift index 95a90232d..9387f4a05 100644 --- a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift @@ -43,8 +43,16 @@ public struct CompletionShell: RawRepresentable, Hashable, CaseIterable { /// Returns an instance representing the current shell, if recognized. public static func autodetected() -> CompletionShell? { // FIXME: This retrieves the user's preferred shell, not necessarily the one currently in use. +#if os(Windows) + var buffer: UnsafeMutablePointer? + var length: Int = 0 + guard _dupenv_s(&buffer, &length, "SHELL") != 0, let shellVar = buffer else { return nil } + let shellParts = String(cString: shellVar).split(separator: "/") + free(buffer) +#else guard let shellVar = getenv("SHELL") else { return nil } let shellParts = String(cString: shellVar).split(separator: "/") +#endif return CompletionShell(rawValue: String(shellParts.last ?? "")) }