Cli

object 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...")
class Object
trait Matchable
class Any

Value members

Concrete methods

def application(usage: String): Application

Creates Application with supplied usage.

Creates Application with supplied usage.

Value Params
usage

usage syntax

def application(usage: String, options: Options): Application

Creates Application with supplied usage and options.

Creates Application with supplied usage and options.

Value Params
options

application options

usage

usage syntax

def application(usage: String, options: Optionable*): Application

Creates Application with supplied usage and options.

Creates Application with supplied usage and options.

Value Params
options

application options

usage

usage syntax

def group(opts: Option*): OptionGroup

Creates new options group with supplied options.

Creates new options group with supplied options.

Value Params
opts

options

def option(opt: String, description: String): Option

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

def option(opt: String, hasArg: Boolean, description: String): 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

def option(opt: String, longOpt: String, hasArg: Boolean, description: String): 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

def options(opts: Optionable*): Options

Creates new options with supplied options.

Creates new options with supplied options.

Value Params
opts

options

def parse(opts: Options, args: Array[String]): CommandLine

Parses arguments according to specified options.

Parses arguments according to specified options.

Value Params
args

arguments

opts

options

def parse(opts: Options, args: Array[String], stoppable: Boolean): CommandLine

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

def printHelp(usage: String, options: Options): Unit

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

def printHelp(usage: String, header: String, options: Options, footer: String): Unit

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

def printHelp(width: Int, usage: String, options: Options): Unit

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

def printHelp(width: Int, usage: String, header: String, options: Options, footer: String): Unit

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

def tryParse(opts: Options, args: Array[String]): Try[CommandLine]

Tries to parse arguments according to specified options.

Tries to parse arguments according to specified options.

Value Params
args

arguments

opts

options

def tryParse(opts: Options, args: Array[String], stoppable: Boolean): Try[CommandLine]

Tries to parse arguments according to specified options.

Tries to parse arguments according to specified options.

Value Params
args

arguments

opts

options

stoppable

specifies whether to stop at first unrecognized argument instead of failing with ParseException