Skip to content

Instantly share code, notes, and snippets.

@ganeshchand
Last active May 14, 2023 22:04
Show Gist options
  • Save ganeshchand/fa703cc5459aa92dd07210ea6d549765 to your computer and use it in GitHub Desktop.
Save ganeshchand/fa703cc5459aa92dd07210ea6d549765 to your computer and use it in GitHub Desktop.
/* scala-cli script
This script is published as part of the blog - https://ganeshchand.com/blog/scala-cli-getting-started
The script demonstrates how to parameterize your scripts and share/run the script as github gist.
How to run this script:
scala-cli https://gist.github.com/ganeshchand/fa703cc5459aa92dd07210ea6d549765 -- "Scala is fun"
*/
// greet with good morning or good afternoon or good evening based on the time of the day
val hour = java.time.LocalTime.now.getHour
val greeting = hour match {
case h if h < 12 => "Good Morning"
case h if h < 16 => "Good Afternoon"
case h if h < 20 => "Good Evening"
case _ => "Good Night"
}
val defaultMessage = "let us live live in peace and harmony"
val message = if(args.isEmpty) defaultMessage else args(0)
println(s"$greeting World, $message!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment