p
The Scala library that provides extension methods to Apache Commons CLI.
The Scala library that provides extension methods to Apache Commons CLI.
Here's an example showing the library in action.
import little.cli.Cli.{ application, option } import little.cli.Implicits._ // Create application with supplied usage and options val app = application("grep [ options ... ] <pattern> [ <fileName> ... ]", option("i", "ignore-case", false, "Perform case insensitive matching"), option("l", "files-with-matches", false, "Print file name only"), option("m", "max-count", true, "Stop reading file after 'num' matches").argName("num"), option("n", "line-number", false, "Include line number of match"), option("r", "recursive", false, "Recursively search subdirectories"), option("x", "exclude", true, "Exclude filename pattern from search").argName("pattern") ) val args = Array("-ilr", "--exclude", "*.swp", "exception", "src/main/scala") // Parse arguments val cmd = app.parse(args) cmd.hasOption("help") match { case true => // Print help to System.out app.printHelp() case false => // Get command arguments and pretend to do something val pattern = cmd.getArg(0) val fileName = cmd.getArg(1) println(s"Searching for files with '$pattern' in $fileName directory...") }