//
//  CliArgsParser.swift
//  Danger
//
//  Created by Franco Meloni on 12/11/2018.
//

import Foundation

public final class CliArgsParser {
    public init() {}
    
    public func parseCli(fromData data: Data) -> CliArgs? {
        if let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String:Any],
            let danger = dictionary?["danger"] as? [String:Any],
            let settings = danger["settings"] as? [String:Any],
            let cliArgsDictionary = settings["cliArgs"] as? [String:Any] {
            return CliArgs(dictionary: cliArgsDictionary)
        }
        
        return nil
    }
}

//
//  CliArgsParser.swift
//  Danger
//
//  Created by Franco Meloni on 12/11/2018.
//

import Foundation

public final class CliArgsParser {
    public init() {}
    
    public func parseCli(fromData data: Data) -> CliArgs? {
        if let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? NSDictionary,
            let cliArgsDictionary = dictionary?.value(forKeyPath: "danger.settings.cliArgs") as? [String:Any] {
            return CliArgs(dictionary: cliArgsDictionary)
        }
        
        return nil
    }
}

--- 
+++ 
@@ -11,8 +11,10 @@
     public init() {}
     
     public func parseCli(fromData data: Data) -> CliArgs? {
-        if let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? NSDictionary,
-            let cliArgsDictionary = dictionary?.value(forKeyPath: "danger.settings.cliArgs") as? [String:Any] {
+        if let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String:Any],
+            let danger = dictionary?["danger"] as? [String:Any],
+            let settings = danger["settings"] as? [String:Any],
+            let cliArgsDictionary = settings["cliArgs"] as? [String:Any] {
             return CliArgs(dictionary: cliArgsDictionary)
         }
         
Remove value(forKeyPath:) method call because is not supported by Linux
