parseKernelspec :: Value -> Parser Kernelspec
parseKernelspec v =
  case v of
    Object o -> do
      dir <- o .: "resource_dir"
      spec <- o .: "spec"
      Kernelspec <$> spec .: "display_name"
                 <*> spec .: "language"
                 <*> (createCommand <$> spec .: "argv")
                 <*> pure (Just $ dir ++ "/kernel.js")
                 <*> pure (Just $ dir ++ "/logo-64x64.png")
                 <*> spec .: "env"
    _ -> fail "Expecting object for kernelspec"
  where
    createCommand :: [Text] -> FilePath -> FilePath -> [String]
    createCommand argv _ connFile =
      flip map argv $ \val ->
        case val of
          "{connection_file}" -> connFile
          _ -> T.unpack val
parseKernelspec :: Value -> Parser Kernelspec
parseKernelspec v =
  case v of
    Object o -> do
      dir <- o .: "resource_dir"
      spec <- o .: "spec"
      Kernelspec <$> spec .: "display_name"
                 <*> spec .: "language"
                 <*> (createCommand <$> spec .: "argv")
                 <*> pure (Just $ dir ++ "/kernel.js")
                 <*> pure (Just $ dir ++ "/logo-64x64.png")
                 <*> spec .: "env"
    _ -> fail "Expecting object for kernelspec"
  where
    createCommand :: [Text] -> FilePath -> FilePath -> [String]
    createCommand argv _ connFile =
      flip map argv $ \val ->
        case val of
          "{connection_file}" -> connFile
          _ -> T.unpack val
parseKernelspec v =
  case v of
    Object o -> do
      dir <- o .: "resource_dir"
      spec <- o .: "spec"
      Kernelspec <$> spec .: "display_name"
                 <*> spec .: "language"
                 <*> (createCommand <$> spec .: "argv")
                 <*> pure (Just $ dir ++ "/kernel.js")
                 <*> pure (Just $ dir ++ "/logo-64x64.png")
                 <*> spec .: "env"
    _ -> fail "Expecting object for kernelspec"
  where
    createCommand :: [Text] -> FilePath -> FilePath -> [String]
    createCommand argv _ connFile =
      flip map argv $ \val ->
        case val of
          "{connection_file}" -> connFile
          _ -> T.unpack val