Cli
Provides factory methods and other utilities.
import little.cli.{ *, given }
import Cli.{ application, option }
// 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...")
Value members
Concrete methods
Creates Application with supplied usage.
Creates Application with supplied usage.
- Value Params
- usage
usage syntax
Creates Application with supplied usage and options.
Creates Application with supplied usage and options.
- Value Params
- options
application options
- usage
usage syntax
Creates Application with supplied usage and options.
Creates Application with supplied usage and options.
- Value Params
- options
application options
- usage
usage syntax
Creates new options group with supplied options.
Creates new options group with supplied options.
- Value Params
- opts
options
Creates new option with supplied short option and description.
Creates new option with supplied short option and description.
- Value Params
- description
option description
- opt
short option
Creates new option with supplied attributes.
Creates new option with supplied attributes.
- Value Params
- description
option description
- hasArg
specifies whether option takes an argument
- opt
short option
Creates new option with supplied attributes.
Creates new option with supplied attributes.
- Value Params
- description
option description
- hasArg
specifies whether option takes an argument
- longOpt
long option
- opt
short option
Creates new options with supplied options.
Creates new options with supplied options.
- Value Params
- opts
options
Parses arguments according to specified options.
Parses arguments according to specified options.
- Value Params
- args
arguments
- opts
options
Parses arguments according to specified options.
Parses arguments according to specified options.
- Value Params
- args
arguments
- opts
options
- stoppable
specifies whether to stop at first unrecognized argument instead of throwing
ParseException
Prints help to Sytem.out
for options
with specified usage
syntax.
Prints help to Sytem.out
for options
with specified usage
syntax.
- Value Params
- options
command options
- usage
usage syntax
Prints help to Sytem.out
for options
with specified usage
syntax.
Prints help to Sytem.out
for options
with specified usage
syntax.
- Value Params
- footer
text to print after options section
- header
text to print before options section
- options
command options
- usage
usage syntax
Prints help to Sytem.out
for options
with specified usage
syntax.
Prints help to Sytem.out
for options
with specified usage
syntax.
- Value Params
- options
command options
- usage
usage syntax
- width
maximum number of characters to print per line
Prints help to Sytem.out
for options
with specified usage
syntax.
Prints help to Sytem.out
for options
with specified usage
syntax.
- Value Params
- footer
text to print after options section
- header
text to print before options section
- options
command options
- usage
usage syntax
- width
maximum number of characters to print per line
Tries to parse arguments according to specified options.
Tries to parse arguments according to specified options.
- Value Params
- args
arguments
- opts
options