File tree Expand file tree Collapse file tree 6 files changed +137
-0
lines changed Expand file tree Collapse file tree 6 files changed +137
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ This library contains all the reference documentation and API reference-related
74
74
* [Bytes](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/bytes.md)
75
75
* [File](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/file.md)
76
76
* [Dir](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/dir.md)
77
+ * [Environmental Variables](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/env.md)
77
78
* [Threading](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/thread.md)
78
79
* [Networking](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/net.md) @kjessup
79
80
* [OAuth2 and Providers](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/OAuth2.md)
Original file line number Diff line number Diff line change 90
90
* [字节流转换](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/bytes.md)
91
91
* [文件操作](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/file.md)
92
92
* [目录与路径](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/dir.md)
93
+ * [环境变量](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/env.md)
93
94
* [线程](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/thread.md)
94
95
* [网络](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/net.md) @kjessup
95
96
* [OAuth2 身份授权](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide.zh_CN/OAuth2.md)
Original file line number Diff line number Diff line change
1
+ # 环境变量
2
+
3
+ ## 使用方法
4
+
5
+ 首先导入PerfectLib:
6
+
7
+ ``` swift
8
+ import PerfectLib
9
+ ```
10
+
11
+ 现在可以在程序中直接调用` Env ` 类对象操作环境变量:
12
+
13
+ ### 设置
14
+
15
+ - 设置一个环境变量
16
+
17
+ 以下操作等同于 bash 命令 "export foo=bar"
18
+
19
+ ``` swift
20
+ Env.set (" foo" , value : " bar" )
21
+ ```
22
+
23
+ - 设置一组环境变量
24
+
25
+ 同样可以使用字典方式设置一组环境变量
26
+
27
+ ``` swift
28
+ Env.set ([" foo" : " bar" , " koo" : " kar" ])
29
+ // 结果等同于 bash 命令 "export foo=bar && export koo=kar"
30
+ ```
31
+
32
+ ### 读取
33
+
34
+ - 查询单个变量:
35
+
36
+ ``` swift
37
+ guard let foo = Env.get (" foo" ) else {
38
+ // 查询失败
39
+ }
40
+ ```
41
+
42
+ - 查询单个变量,并附加默认值(如果不存在这个变量就用默认值代替)
43
+
44
+ ``` swift
45
+ guard let foo = Env.get (" foo" , defaultValue : " bar" ) else {
46
+ // 既然有默认值,则查询应该不会失败
47
+ }
48
+ ```
49
+
50
+ - 查询所有系统变量
51
+
52
+ ``` swift
53
+ let all = Env.get ()
54
+ // 结果是一个字典 [String: String]
55
+ ```
56
+
57
+ ### 删除
58
+
59
+ - 删除一个环境变量:
60
+
61
+
62
+ ``` swift
63
+ Env.del (" foo" )
64
+ ```
Original file line number Diff line number Diff line change 136
136
"name" : " 目录与路径" ,
137
137
"doc" : " dir"
138
138
},
139
+ {
140
+ "name" : " 环境变量" ,
141
+ "doc" : " env"
142
+ },
139
143
{
140
144
"name" : " 文件操作" ,
141
145
"doc" : " file"
Original file line number Diff line number Diff line change
1
+ # Environmental Operations
2
+
3
+ ## Usage
4
+
5
+ First, ensure the ` PerfectLib ` is imported in your Swift file:
6
+
7
+ ``` swift
8
+ import PerfectLib
9
+ ```
10
+ You are now able to use the ` Env ` class to operate the environmental variables
11
+
12
+ ### Set
13
+
14
+ - Single Variable Setting:
15
+
16
+ This statement is equal to bash command "export foo=bar"
17
+
18
+ ``` swift
19
+ Env.set (" foo" , value : " bar" )
20
+ ```
21
+
22
+ - Group Setting:
23
+
24
+ It is also possible to set a group of variables in a dictionary style:
25
+
26
+ ``` swift
27
+ Env.set ([" foo" : " bar" , " koo" : " kar" ])
28
+ // the result is identically the same as "export foo=bar && export koo=kar"
29
+ ```
30
+
31
+ ### Get
32
+
33
+ - Single variable query:
34
+
35
+ ``` swift
36
+ guard let foo = Env.get (" foo" ) else {
37
+ // there is no such a variable
38
+ }
39
+ ```
40
+
41
+ - Single variable query with a default value:
42
+
43
+ ``` swift
44
+ guard let foo = Env.get (" foo" , defaultValue : " bar" ) else {
45
+ // there is no such a variable even with a default value??
46
+ }
47
+ ```
48
+
49
+ - Query all system variables:
50
+
51
+ ``` swift
52
+ let all = Env.get ()
53
+ // the result of all is a dictionary [String: String]
54
+ ```
55
+
56
+ ### Delete
57
+
58
+ - Delete an environmental variable:
59
+
60
+
61
+ ``` swift
62
+ Env.del (" foo" )
63
+ ```
Original file line number Diff line number Diff line change 136
136
"name" : " Dir" ,
137
137
"doc" : " dir"
138
138
},
139
+ {
140
+ "name" : " Environmental Variables" ,
141
+ "doc" : " env"
142
+ },
139
143
{
140
144
"name" : " File" ,
141
145
"doc" : " file"
You can’t perform that action at this time.
0 commit comments