fun main()

in firestore/src/main/kotlin/Firestore.kt [19:47]


fun main(vararg args: String) {
    // validate the arguments
    if (args.isEmpty() || args.size > 3) {
        throw Exception("Usage: java -jar firestore.jar YOUR_COLLECTION_ID [KEY] [VALUE]")
    }

    // create the client
    val db = FirestoreOptions.newBuilder()
        .build()
        .service

    // create the docRef and data object
    val docRef = db.collection(args[0]).document("samples")
    val data = docRef
        .get() // future
        .get() // snapshot
        .data // MutableMap

    // If no arguments are supplied, call the quickstart. Fetch the key value if only one argument is supplied.
    // Set the key to the supplied value if two arguments are supplied.
    when (args.size) {
        1 -> quickstart(args[0], "samples")
        2 -> println("${args[1]}: ${data?.get(args[1]) ?: "not found"}")
        else -> {
            val future = docRef.update(args[1], args[2])
            println("Updated collection: ${future.get()}")
        }
    }
}