From 013c82e97b777a0d427e65908f9ad545347b52c7 Mon Sep 17 00:00:00 2001 From: Abhay Menon <a32menon@uwaterloo.ca> Date: Sat, 11 Feb 2023 01:42:11 -0500 Subject: [PATCH] Added pseudocode for handling user arguments --- .idea/.gitignore | 1 + .../kotlin/notes/multi/console/Console.kt | 61 +++++++++++++++++-- .../notes/multi/console/MessageUtils.kt | 14 +++++ 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/.idea/.gitignore b/.idea/.gitignore index 26d3352..050d725 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,4 @@ # Default ignored files /shelf/ /workspace.xml +codeStyles/ \ No newline at end of file diff --git a/console/src/main/kotlin/notes/multi/console/Console.kt b/console/src/main/kotlin/notes/multi/console/Console.kt index 6999949..3eeb7d0 100644 --- a/console/src/main/kotlin/notes/multi/console/Console.kt +++ b/console/src/main/kotlin/notes/multi/console/Console.kt @@ -3,10 +3,63 @@ */ package notes.multi.console -import notes.multi.utilities.StringUtils +import notes.multi.app.MessageUtils +import notes.multi.utilities.Filemanager +import java.lang.IllegalArgumentException -import org.apache.commons.text.WordUtils +fun main(args: Array<String>) { + + if(args.isEmpty()) { + println(""" + +-------------------------------------------------------------------------------------+ + WELCOME TO TEAM 112'S CONSOLE BASED NOTES APP + + This application is a working console-based prototype for the + note taking application that the team will be delivering at the end of the term. + + With this simple app, users can: + 1. Create Notes + 2. Edit Notes + 3. Delete Notes + + 1. Create Notes + - To create notes, users must type "notes <filename>" + + 2. Edit Notes + - To edit notes, users must type "notes <filename>" + - If the file doesn't exist, a new note will be created + + 3. Delete Notes + - To delete a note, users must type "notes -d <filename>" + - If the user tries to delete a note that doesn't exist, + the app will display an error message + +-------------------------------------------------------------------------------------+ + """.trimIndent()) + } else { + if (args.size < 2) { + val filename = args[0] + // Optional Regex Check for a specific argument format: + MessageUtils.verifyFilename(filename, Regex("^.*[.](md|txt)$")) + // if (fileExists) { + // Filemanager(".").editfile() + // } else { + // Filemanager(".").createfile() + // } + } else { + if (args[0] != "-d") { + throw IllegalArgumentException("[ERROR]: First parameter must be the delete flag") + } else { + val filename = args[1] + + // Optional Regex Check for a specific argument format: + MessageUtils.verifyFilename(filename, Regex("^.*[.](md|txt)$")) + // if (fileExists) { + // Filemanager(".").deletefile() + // } else { + // throw IllegalArgumentException("[ERROR]: File must exist for it to be deleted") + // } + } + } + } -fun main() { - println("this is multi setup") } diff --git a/console/src/main/kotlin/notes/multi/console/MessageUtils.kt b/console/src/main/kotlin/notes/multi/console/MessageUtils.kt index 0cca4da..6e9dd5e 100644 --- a/console/src/main/kotlin/notes/multi/console/MessageUtils.kt +++ b/console/src/main/kotlin/notes/multi/console/MessageUtils.kt @@ -2,9 +2,23 @@ * This Kotlin source file was generated by the Gradle 'init' task. */ package notes.multi.app +import java.lang.IllegalArgumentException class MessageUtils { companion object { fun getMessage(): String = "Hello World!" + + /** + * Checks the `filename` inputted and throws an exception + * if the `filename` does not follow the regular expression `pattern` + * @param filename Name of the file + * @param pattern Regular expression pattern + */ + fun verifyFilename(filename: String, pattern: Regex) { + if (!(pattern matches filename)) { + System.err.println("[ERROR]: File name does not follow the required input pattern") + throw IllegalArgumentException("[ERROR]: File name does not follow the required input pattern") + } + } } } -- GitLab