/** * TICKETS * * a Linux cli for the mini ticket system written in C * features: * - create a ticket * `tickets create <description>` * - list all tickets (or filter by status) * `tickets list --status=(open|in_progress|closed)` * - detail of one ticket * `tickets detail <id>` */ fun showUsage() { println("usage:\n" + " tickets create <title> <description>\n" + " tickets list --status (open|in_progress|closed)\n" + " tickets detail <id>\n") } fun parseCreate(title: String, description: String) { println("CREATE: creating a ticket with\n" + "title='$title'\n" + "description='$description'") } fun parseList(status: String) { println("LIST: listing items with status '$status'") } fun parseDetail(id: Int) { println("ID: the id i got is $id\ngoodbye!") } fun main(args: Array<String>) { // only program name if (args.isEmpty()) { showUsage() return } // args.size > 1 // status filter or no filter if (args[0] == "list") { if (args.size >= 3 && args[1] == "--status") { parseList(args[2]) } else { parseList("") } return } if (args.size >= 2 && args[0] == "detail") { val id = args[1].toIntOrNull() if (id == null) { showUsage() return } else { parseDetail(id) } return } if (args.size >= 3 && args[0] == "create") { parseCreate(args[1], args[2]) } else { showUsage() return } }