Oberon: Subcommand Program Options

Subcommands

Subcommands are an effective way of making a complex command line application easier to use. The essential idea is that the high level capabilities of the application are separated, each having their own distinct options and focussed purpose. Once an application reaches a certain amount of complexity it becomes exceedingly difficult to use without this separation. Probably the most well known application to utilise this technique is Subversion (svn).

Oberon is built on top of Boost.Program_options, is available under the permissive Apache 2.0 license and is written in modern C++. It is named Oberon after a type of submarine.

Download the latest version
Project page on BitBucket.org

A Basic Example

The example output below is for a contrived application that allows you to manipulate a single character (e.g. a, c, z etc) in an input string.

radman@computer:$ ./oberon_basic_2
Application that can manipulate one character in a string in a couple of ways
USAGE: CharManipulator [--version] [subcommand]

--version Display version information

subcommand The subcommand to execute, see below:
help
randomise
remove


There are two subcommands for the application; randomise or remove. One allows you to replace the character with a randomly generated one and the other lets you remove it. Each command has slightly different nuances as you can see in their help text below:


radman@computer:$ ./oberon_basic_2 help remove
Subcommand: remove

remove a character from the provided string
USAGE: remove [-N] targetChar inputString

targetChar Character type to operate on within the string
inputString String for the application to operate on

-N [ --no-collapse ] Removal leaves a space

radman@computer:$ ./oberon_basic_2 help randomise
Subcommand: randomise

randomise a character from the provided string
USAGE: randomise [-cCns] targetChar inputString

targetChar Character type to operate on within the string
inputString String for the application to operate on

-c [ --with-lowerchar ] Include lower case characters
-C [ --with-upperchar ] Include upper case characters
-n [ --with-numbers ] Include numbers
-s [ --with-symbols ] Include symbols


It should also be apparent that without subcommands separating the options would become painful, you would even need an option to signal whether you were randomising or replacing! With subcommands this is relatively clean and nicely separated.

Oberon

Oberon is open source and is hosted on BitBucket. If you have an issue with the library see the issue tracker, need information on Oberon itself; check out the wiki and if you just want the latest version of the source code get it here. If you have a question you would like answered just leave a comment on this page. Any and all feedback is greatly appreciated.

I hope you find Oberon as useful and easy to use as I do!

One Response to “Oberon: Subcommand Program Options”


Leave a Comment