This repository was archived by the owner on Oct 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
CodeReady Containers/KubeSwitch Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -19,27 +19,35 @@ class KubeConfig {
19
19
}
20
20
21
21
func currentContext( ) -> String {
22
- return ( self . yamlContent [ " current-context " ] != nil )
23
- ? self . yamlContent [ " current-context " ] as! String : " "
22
+ if let ret = self . yamlContent [ " current-context " ] as? String {
23
+ return ret
24
+ } else {
25
+ return " "
26
+ }
24
27
}
25
28
26
29
func isCurrentContext( otherContextName: String ) -> Bool {
27
30
return otherContextName == self . currentContext ( )
28
31
}
29
32
30
33
func contexts( ) -> [ AnyObject ] {
31
- return ( self . yamlContent [ " contexts " ] != nil )
32
- ? self . yamlContent [ " contexts " ] as! [ AnyObject ] : [ ]
34
+ if let ret = self . yamlContent [ " contexts " ] as? [ AnyObject ] {
35
+ return ret
36
+ } else {
37
+ return [ ]
38
+ }
33
39
}
34
40
35
41
func contextNames( ) -> [ String ] {
36
42
return self . contexts ( )
37
43
. map {
38
- $0 as! [ String : Any ]
44
+ $0 as? [ String : Any ]
39
45
}
46
+ . compactMap { $0 }
40
47
. map {
41
- $0 [ " name " ] as! String
48
+ $0 [ " name " ] as? String
42
49
}
50
+ . compactMap { $0 }
43
51
}
44
52
45
53
func changeContext( newContext: String ) {
Original file line number Diff line number Diff line change @@ -18,8 +18,11 @@ class YamlReader {
18
18
func loadKubeConfig( yaml: String ) -> KubeConfig {
19
19
do {
20
20
let readYaml = try Yams . load ( yaml: yaml)
21
- let yamlContent = readYaml != nil ? readYaml as! [ String : Any ] : [ : ]
22
- return KubeConfig ( yamlContent: yamlContent)
21
+ if let ret = readYaml as? [ String : Any ] {
22
+ return KubeConfig ( yamlContent: ret)
23
+ } else {
24
+ return KubeConfig ( yamlContent: [ : ] )
25
+ }
23
26
} catch {
24
27
os_log ( " Could not load yaml string as dictionary " , type: . error)
25
28
let errorDetails = " \( error) "
You can’t perform that action at this time.
0 commit comments