Search results

There are no results.

std.optparse.Help

class pub Help

A type for generating help messages easily.

Examples

A simple but complete overview of how to use this type:

import optparse.(Help, Options)

let opts = Options.new

opts.flag('h', 'help', 'Show this help message')
opts.flag('v', 'version', 'Show the version')

Help
  .new('a')
  .description('This is an example')
  .section('Examples')
  .line('foo')
  .line('bar')
  .section('Options')
  .options(opts)
  .to_string

This returns the following:

a: [OPTIONS]

This is an example

Examples:

  foo
  bar

Options:

  -h, --help       Show this help message
  -v, --version    Show the version

Static methods

new

Show source code
Hide source code
fn pub static new(name: String) -> Help {
  Help(
    name: name,
    description: '',
    usage: '[OPTIONS]',
    lines: StringBuffer.new,
  )
}
fn pub static new(name: String) -> Help

Returns a new Help instance with the given program name.

Examples

import optparse.Help

Help.new('ls')

Instance methods

description

Show source code
Hide source code
fn pub mut description(value: String) -> mut Help {
  @description = value
  self
}
fn pub mut description(value: String) -> mut Help

Sets the description of the command.

Unlike Help.line(), the text isn't indented, and always comes after the usage line.

Examples

import optparse.Help

Help.new('ls').description('List files and folders')

line

Show source code
Hide source code
fn pub mut line(value: String) -> mut Help {
  @lines.push(INDENT)
  @lines.push(value)
  @lines.push('\n')
  self
}
fn pub mut line(value: String) -> mut Help

Adds a regular line to the output.

Indentation is added automatically to the start of the line.

Examples

import optparse.Help

Help.new('ls').section('Examples').line('ls # Show files and folders')

options

Show source code
Hide source code
fn pub mut options(value: ref Options) -> mut Help {
  @lines.push(value.to_string)
  @lines.push('\n')
  self
}
fn pub mut options(value: ref Options) -> mut Help

Formats and adds a list of options to the output.

Examples

import optparse.(Help, Options)

let opts = Options.new

opts.flag('h', 'help', 'Show this help message')

Help.new('ls').options(opts)

section

Show source code
Hide source code
fn pub mut section(name: String) -> mut Help {
  @lines.push('\n')
  @lines.push(name)
  @lines.push(':\n\n')
  self
}
fn pub mut section(name: String) -> mut Help

Adds a section to the output.

Examples

import optparse.Help

Help.new('ls').section('Examples')

to_string

Show source code
Hide source code
fn pub to_string -> String {
  let out = StringBuffer.from_array(['Usage: ', @name, ' ', @usage, '\n'])

  if @description.size > 0 {
    out.push('\n')
    out.push(@description)
    out.push('\n')
  }

  out.push(@lines.to_string)
  out.into_string
}
fn pub to_string -> String

Converts self to a String.

usage

Show source code
Hide source code
fn pub mut usage(value: String) -> mut Help {
  @usage = value
  self
}
fn pub mut usage(value: String) -> mut Help

Sets the usage String to the given argument.

Examples

import optparse.Help

Help.new('ls').usage('[OPTIONS]')

Implemented traits

std.string.

ToString

impl ToString for Help