class::sys::Cli

class sys::Cli
  : public api::WorkObject

This class contains methods to help analyze input from the command line.

Summary

Cli(

int argc,
char * argv,
const var::ConstString & app_git_hash
)

const var::String app_git_hash() const

var::String at(

u16 value
) const

u32 count() const

var::String get_option(

const arg::OptionName name,
const arg::OptionDescription help
) const

var::String get_option_argument(

const char * option
) const

int get_option_hex_value(

const char * option
) const

mcu_pin_t get_option_pin(

const char * option
) const

int get_option_value(

const char * option
) const

var::String get_version_details() const

bool handle_i2c(

hal::I2CAttr & attr
) const

bool handle_uart(

hal::UartAttributes & attr
) const

void handle_version() const

bool is_case_senstive() const

bool is_option(

const var::ConstString & value
) const

const var::String name() const

const var::String path() const

mcu_pin_t pin_at(

u16 value
) const

const var::String publisher() const

void set_case_sensitive(

bool value
)

void set_publisher(

const var::ConstString & publisher
)

void show_options() const

u32 size() const

var::String to_string() const

int value_at(

u16 value
) const

const var::String & version() const

enum @14

enum @15

Members

Cli(

int argc,
char * argv,
const var::ConstString & app_git_hash
)

Constructs a new object to parse and handle command line interface arguments.

Parameters

  • argc The number of arguments

  • argv A pointer to the arguments

The Cli is construted as shown in the following example.

int main(int argc, char * argv[]){
   Cli cli(argc, argv);
}

const var::String app_git_hash() const

Accesses the path to the program (including the name).


var::String at(

u16 value
) const

Returns the argument offset by value as a var::String.


u32 count() const

Returns the number of arguments.


var::String get_option(

const arg::OptionName name,
const arg::OptionDescription help
) const

Checks to see if the option exists and returns its value as a String.

Parameters

  • name The option name

This method will work with the following notations

-<name>
-<name> <value>
-<name>=<value>
--<name>
--<name> <value>
--<name>=<value>

If -<name> or --<name> is given, the return value is set to “true”.


var::String get_option_argument(

const char * option
) const

Gets the argument of an option as a var::String.

Parameters

  • option The option to match

Returns

A String containing the option argument

For example, take the given command line

program -i filename.txt

get_option_argument("-i") will return a String containing “filename.txt”


int get_option_hex_value(

const char * option
) const

Gets the argument of an option as a var::String.

Parameters

  • option The option to match

Returns

The value of the argument or 0 if the option wasn’t found

For example, take the given command line

program -i 0x40

get_option_hex_value("-i") will return 0x40 (64 decimal).


mcu_pin_t get_option_pin(

const char * option
) const

Gets the argument of an option as a var::String.

Parameters

  • option The option to match

Returns

The value of the argument or 0 if the option wasn’t found SOS_GIT_HASH=“${SOS_GIT_HASH}” For example, take the given command line

program -i 2.1

get_option_pio("-i") will return a mcu_pin_t structure with port = 2 and pin = 1.


int get_option_value(

const char * option
) const

Gets the argument of an option as a var::String.

Parameters

  • option The option to match

Returns

The value of the argument or 0 if the option wasn’t found

For example, take the given command line

program -i 10

get_option_value("-i") will return 10.


var::String get_version_details() const

bool handle_i2c(

hal::I2CAttr & attr
) const

Handles arguments for setting I2C attributes.

Parameters

  • attr A reference to the destination attributes

Returns

true if I2C attributes were parsed

The arguments are

  • ”-i2c [port]” (required)
  • ”-freq [bitrate]” (optional, default is 100000)
  • ”-slave” (optional, default is 0)
  • ”-scl [X.Y]” (optional port.pin, uses system default otherwise)
  • ”-sda [X.Y]” (optional port.pin, uses system default otherwise)
  • ”-pu” (optional flag, use internal pullup resistors)

bool handle_uart(

hal::UartAttributes & attr
) const

Handles arguments for setting UART attributes.

Parameters

  • attr A reference to the destination attributes

Returns

true if UART attributes were parsed

The arguments are

  • ”-uart [port]” (required)
  • ”-freq [bitrate]” (optional, default is 115200)
  • ”-width [byte width]” (optional, default is 8)
  • ”-stop1” (optional, default is 1 stop bit)
  • ”-stop2” (optional)
  • ”-tx [X.Y]” (optional port.pin, uses system default otherwise)
  • ”-rx [X.Y]” (optional port.pin, uses system default otherwise)
  • ”-rts [X.Y]” (optional port.pin, uses system default otherwise)
  • ”-cts [X.Y]” (optional port.pin, uses system default otherwise)

void handle_version() const

Handles the –version and -v options to show the version.

See also: print_version()


bool is_case_senstive() const

Returns true if parsing is case sensitive.

By default, parsing is case senstive unless set_case_sensitive(false) is called.


bool is_option(

const var::ConstString & value
) const

Checks to see if the option exists as a command line argument.

Parameters

  • value A pointer to the option string to search for

Returns

True if value is any of the options available

For example,

program -v -i text.txt

is_option("-v") will return true.


const var::String name() const

Accesses the program name.


const var::String path() const

Accesses the path to the program (including the name).


mcu_pin_t pin_at(

u16 value
) const

Returns the argument offset by value as a mcu_pin_t value.


const var::String publisher() const

Accesses the program publisher.


void set_case_sensitive(

bool value
)

Sets whether the arguments are case sensitive.


void set_publisher(

const var::ConstString & publisher
)

Sets the publisher of the program.

Parameters

  • publisher A pointer to the publisher’s name

void show_options() const

u32 size() const

var::String to_string() const

int value_at(

u16 value
) const

Return the argument offset by value as an int value


const var::String & version() const

Accesses the program version.


enum @14
  • FORMAT_TEXT
  • FORMAT_JSON
  • FORMAT_TOTAL

enum @15
  • PRINT_DEBUG
  • PRINT_INFO
  • PRINT_WARNING
  • PRINT_ERROR
  • PRINT_FATAL
  • PRINT_TOTAL

X

Thanks for Coming!

Subscribe to news and updates