Sha256: d081e0f9868a8f689b0c2bdad2b3f265ef1688cc022871b55f01e2062b002b13

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

= Command Definition using Method Notation

Require commandline library.

  require 'clio/commandline'

Since this not a real command line application,
lets fake one called 'test'.

    $0 = 'test'

We can use a method to define a subcommand.

    cmd = Clio::Commandline.new
    cmd.usage.doc
    cmd.to_s.assert == 'test doc'

We can use a question-method to define a switch.

    cmd = Clio::Commandline.new
    cmd.usage.doc
    cmd.usage.verbose?
    cmd.to_s.assert == 'test [--verbose] doc'

The switch method can also take option aliases.

    cmd = Clio::Commandline.new
    cmd.usage.verbose?(:v)
    cmd.to_s.assert == 'test [-v --verbose]'

The command can take argument to process as suboptions
and arguments.

    cmd = Clio::Commandline.new
    cmd.usage.doc('--output=PATH')
    cmd.to_s.assert == 'test doc [--output=PATH]'
    cmd.usage.doc.to_s.assert == 'doc [--output=PATH]'

An option and a subcommand parsed statically.

    cmd = Clio::Commandline.new
    cmd.usage.doc('--output=PATH')
    cmd.usage.verbose?(:v)
    cmd.to_s.assert == 'test [-v --verbose] doc [--output=PATH]'

We can define help for these commands and options using
a seaprate help! call.

    cmd = Clio::Commandline.new
    cmd.usage.doc('--output=PATH')
    cmd.usage.verbose?(:v)

    cmd.usage.help!(
      'doc', 'generate documentation',
      '--verbose', 'verbose mode'
    )

    cmd.usage.options[0].name.assert == 'verbose'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clio-0.3.0 spec/commandline/method.rd