This commit is contained in:
Erik C. Thauvin 2020-07-24 18:01:46 -07:00
parent 449622cd8f
commit 82e18d29a8

View file

@ -1,21 +1,24 @@
package com.example
import java.io.File
import net.thauvin.erik.readingtime.ReadingTime
import net.thauvin.erik.readingtime.ReadingTime.Companion.imgCount
import net.thauvin.erik.readingtime.ReadingTime.Companion.wordCount
import java.io.File
fun main(args: Array<String>) {
if (args.isNotEmpty()) {
val text = File(args[0])
if (text.exists() && text.canRead()) {
val rt = ReadingTime(text.readText())
rt.postfix = "minute to read"
rt.plural = "minutes to read"
with(File(args[0])) {
if (exists() && canRead()) {
val rt = ReadingTime(readText())
rt.postfix = "minute to read"
rt.plural = "minutes to read"
println("It will take ${rt.calcReadingTime()} ${wordCount(rt.text)} words and ${imgCount(rt.text)} images.")
} else {
System.err.println("The file could not be read or found.")
println(
"It will take ${rt.calcReadingTime()} ${wordCount(rt.text)} words and ${imgCount(rt.text)} images."
)
} else {
System.err.println("The file could not be read or found.")
}
}
} else {
System.err.println("Please specify a file as an argument.")