- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathCommandLine.swift
51 lines (45 loc) · 1.9 KB
/
CommandLine.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import SwiftShims
/// Command-line arguments for the current process.
@frozen // namespace
publicenumCommandLine{
/// The backing static variable for argument count may come either from the
/// entry point or it may need to be computed e.g. if we're in the REPL.
@usableFromInline
internalstaticvar_argc:Int32=Int32()
/// The backing static variable for arguments may come either from the
/// entry point or it may need to be computed e.g. if we're in the REPL.
///
/// Care must be taken to ensure that `_swift_stdlib_getUnsafeArgvArgc` is
/// not invoked more times than is necessary (at most once).
@usableFromInline
internalstaticvar_unsafeArgv:
UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>
=_swift_stdlib_getUnsafeArgvArgc(&_argc)
/// Access to the raw argc value from C.
publicstaticvarargc:Int32{
_ =CommandLine.unsafeArgv // Force evaluation of argv.
return _argc
}
/// Access to the raw argv value from C. Accessing the argument vector
/// through this pointer is unsafe.
publicstaticvarunsafeArgv:
UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>{
return _unsafeArgv
}
/// Access to the Swift command line arguments.
// Use lazy initialization of static properties to
// safely initialize the swift arguments.
publicstaticvararguments:[String]
=(0..<Int(argc)).map{String(cString:_unsafeArgv[$0]!)}
}