xorp

CliCommand Class Reference

The class for the CLI command. More...

#include <cli_command.hh>

Inheritance diagram for CliCommand:
CliPipe

List of all members.

Public Types

typedef XorpCallback2< bool,
const string &, string & >
::RefPtr 
TypeMatchCb

Public Member Functions

 CliCommand (CliCommand *init_parent_command, const string &init_command_name, const string &init_command_help)
 Constructor for a given parent command, command name, and command help.
virtual ~CliCommand ()
 Destructor.
void set_allow_cd (bool v, const string &init_cd_prompt)
 Enable/disable whether this command allows "change directory" to it.
int create_default_cli_commands ()
 Create the default CLI commands at each level of the command tree.
int add_pipes (string &error_msg)
 Create and add the default CLI pipe commands.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, bool is_multilevel_command, string &error_msg)
 Add a CLI command.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, const string &init_cd_prompt, bool is_multilevel_command, string &error_msg)
 Add a CLI command we can "cd" to it.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, bool is_multilevel_command, const CLI_PROCESS_CALLBACK &init_cli_process_callback, string &error_msg)
 Add a CLI command with a processing callback.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, bool is_multilevel_command, const CLI_PROCESS_CALLBACK &init_cli_process_callback, const CLI_INTERRUPT_CALLBACK &init_cli_interrupt_callback, string &error_msg)
 Add a CLI command with a processing and an interrupt callbacks.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, bool is_multilevel_command, CLI_PROCESS_FUNC init_cli_process_func, string &error_msg)
 Add a CLI command with a processing function.
CliCommandadd_command (const string &init_command_name, const string &init_command_help, bool is_multilevel_command, CLI_PROCESS_FUNC init_cli_process_func, CLI_INTERRUPT_FUNC init_cli_interrupt_func, string &error_msg)
 Add a CLI command with a processing function and an interrupt handler.
int add_command (CliCommand *child_command, string &error_msg)
 Add a child CLI command.
int delete_command (CliCommand *child_command)
 Delete a child command and all sub-commands below it.
int delete_command (const string &delete_command_name)
 Delete a child command and all sub-commands below it.
void delete_all_commands ()
 Recursively delete all children of this command.
void set_can_pipe (bool v)
 Set whether the output of this command can be piped.
bool default_nomore_mode () const
 Test if "no-more" (i.e., unpaged) is the default output mode.
void set_default_nomore_mode (bool v)
 Set the default paging mode.
bool is_command_argument () const
 Test if the command actually represents a command argument.
void set_is_command_argument (bool v)
 Set a flag whether the command actually represents a command argument.
bool is_argument_expected () const
 Test if the command expects an argument.
void set_is_argument_expected (bool v)
 Set a flag whether the command expects an argument.
const TypeMatchCb & type_match_cb () const
 Get the callback for type matching.
void set_type_match_cb (const TypeMatchCb &cb)
 Set the callback for type matching.
bool has_type_match_cb () const
 Test if there is a callback for type matching.
const vector< string > & global_name () const
 Get the global name of this command (i.e., the full name starting from the root).
void set_global_name (const vector< string > &v)
 Set the global name for this command.
const string & server_name () const
 Get the server (i.e., processor) name for this command.
void set_server_name (const string &v)
 Set the server (i.e., processor) name for this command.
void set_dynamic_children_callback (DYNAMIC_CHILDREN_CALLBACK v)
 Set the callback for dynamic generation of children commands.
void set_dynamic_process_callback (const CLI_PROCESS_CALLBACK &v)
 Set the callback for command processing for a dynamically generated child command.
void set_dynamic_interrupt_callback (const CLI_INTERRUPT_CALLBACK &v)
 Set the callback for command interrupt for a dynamically generated child command.
void set_cli_process_callback (const CLI_PROCESS_CALLBACK &v)
 Set the callback for command processing.
void set_cli_interrupt_callback (const CLI_INTERRUPT_CALLBACK &v)
 Set the callback for command interrupt.

Private Member Functions

const string & name () const
const string & cd_prompt ()
list< CliCommand * > & child_command_list ()
const string & help () const
const string & help_completion () const
int delete_pipes ()
 CliCommand::delete_pipes: @:
bool is_same_prefix (const string &token)
bool is_same_command (const string &token)
CliCommandcommand_find (const string &token)
bool is_multi_command_prefix (const string &command_line)
bool find_command_help (const char *line, int word_end, set< string > &help_strings)
bool allow_cd ()
bool has_cli_process_callback ()
bool has_cli_interrupt_callback ()
bool has_dynamic_process_callback ()
bool has_dynamic_interrupt_callback ()
bool has_cli_completion_func ()
void set_cli_completion_func (CLI_COMPLETION_FUNC *v)
bool can_complete ()
bool can_pipe () const
CliCommandcli_command_pipe ()
void set_cli_command_pipe (CliCommand *v)
CliCommandroot_command ()
void set_root_command (CliCommand *v)

Static Private Member Functions

static bool cli_attempt_command_completion_byname (void *obj, WordCompletion *cpl, void *data, const char *line, int word_end, list< CliCommand * > &cli_command_match_list)

Private Attributes

CLI_PROCESS_CALLBACK _cli_process_callback
CLI_INTERRUPT_CALLBACK _cli_interrupt_callback
CLI_COMPLETION_FUNC * _cli_completion_func
DYNAMIC_CHILDREN_CALLBACK _dynamic_children_callback
bool _has_dynamic_children
CLI_PROCESS_CALLBACK _dynamic_process_callback
CLI_INTERRUPT_CALLBACK _dynamic_interrupt_callback
CliCommand_root_command
CliCommand_parent_command
list< CliCommand * > _child_command_list
const string _name
const string _help
vector< string > _global_name
string _server_name
string _help_completion
bool _allow_cd
string _cd_prompt
bool _can_pipe
bool _default_nomore_mode
bool _is_command_argument
bool _is_argument_expected
CliCommand_cli_command_pipe
TypeMatchCb _type_match_cb

Friends

class CliClient

Detailed Description

The class for the CLI command.


Constructor & Destructor Documentation

CliCommand::CliCommand ( CliCommand init_parent_command,
const string &  init_command_name,
const string &  init_command_help 
)

Constructor for a given parent command, command name, and command help.

Parameters:
init_parent_commandthe parent CliCommand command.
init_command_namethe command name (this name should not include the command name of the parent command and its ancestors).
init_command_helpthe command help.

Member Function Documentation

CliCommand * CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
bool  is_multilevel_command,
string &  error_msg 
)

Add a CLI command.

By default, we cannot "cd" to this command.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "show version pim". However, commands "show" and "show version" must have been installed first.
init_command_helpthe command help.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
CliCommand * CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
const string &  init_cd_prompt,
bool  is_multilevel_command,
string &  error_msg 
)

Add a CLI command we can "cd" to it.

By default, we can "cd" to this command.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "set pim bsr". However, commands "set" and "set pim" must have been installed first.
init_command_helpthe command help.
init_cd_promptif not an empty string, the CLI prompt when "cd" to this command.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
CliCommand* CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
bool  is_multilevel_command,
CLI_PROCESS_FUNC  init_cli_process_func,
string &  error_msg 
) [inline]

Add a CLI command with a processing function.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "show version pim". However, commands "show" and "show version" must have been installed first.
init_command_helpthe command help.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
init_cli_process_functhe processing function to call when the command is entered for execution from the command-line.
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
CliCommand* CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
bool  is_multilevel_command,
CLI_PROCESS_FUNC  init_cli_process_func,
CLI_INTERRUPT_FUNC  init_cli_interrupt_func,
string &  error_msg 
) [inline]

Add a CLI command with a processing function and an interrupt handler.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "show version pim". However, commands "show" and "show version" must have been installed first.
init_command_helpthe command help.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
init_cli_process_functhe processing function to call when the command is entered for execution from the command-line.
init_cli_interrupt_functhe function to call when the user has interrupted the command (e.g., by typing Ctrl-C).
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
int CliCommand::add_command ( CliCommand child_command,
string &  error_msg 
)

Add a child CLI command.

Parameters:
child_commandthe child command to add.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
CliCommand * CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
bool  is_multilevel_command,
const CLI_PROCESS_CALLBACK &  init_cli_process_callback,
string &  error_msg 
)

Add a CLI command with a processing callback.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "show version pim". However, commands "show" and "show version" must have been installed first.
init_command_helpthe command help.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
init_cli_process_callbackthe callback to call when the command is entered for execution from the command-line.
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
CliCommand * CliCommand::add_command ( const string &  init_command_name,
const string &  init_command_help,
bool  is_multilevel_command,
const CLI_PROCESS_CALLBACK &  init_cli_process_callback,
const CLI_INTERRUPT_CALLBACK &  init_cli_interrupt_callback,
string &  error_msg 
)

Add a CLI command with a processing and an interrupt callbacks.

Parameters:
init_command_namethe command name to add. If is_multilevel_command is true, then it may include more than one command levels in the middle. E.g., "show version pim". However, commands "show" and "show version" must have been installed first.
init_command_helpthe command help.
is_multilevel_commandif true, then init_command_name may include more than one command levels in the middle.
init_cli_process_callbackthe callback to call when the command is entered for execution from the command-line.
init_cli_interrupt_callbackthe callback to call when the user has interrupted the command (e.g., by typing Ctrl-C).
error_msgthe error message (if error).
Returns:
the new child command on success, otherwise NULL.
int CliCommand::add_pipes ( string &  error_msg)

Create and add the default CLI pipe commands.

CliCommand::add_pipes: @:

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Create and add the default CLI pipe commands.

Return value: XORP_OK on success, otherwise XORP_ERROR.

int CliCommand::create_default_cli_commands ( )

Create the default CLI commands at each level of the command tree.

CliCommand::create_default_cli_commands: @:

Returns:
XORP_OK on success, otherwise XORP_ERROR.

Create the default CLI commands at each level of the command tree.

Return value: XORP_OK on success, otherwise XORP_ERROR.

bool CliCommand::default_nomore_mode ( ) const [inline]

Test if "no-more" (i.e., unpaged) is the default output mode.

Returns:
true if "no-more" (i.e., unpaged) is the default output mode, otherwise false.
int CliCommand::delete_command ( CliCommand child_command)

Delete a child command and all sub-commands below it.

Parameters:
child_commandthe child command to delete.
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int CliCommand::delete_command ( const string &  delete_command_name)

Delete a child command and all sub-commands below it.

Parameters:
delete_command_namethe name of the child command to delete. The name can be the full path-name for that command.
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int CliCommand::delete_pipes ( ) [private]

CliCommand::delete_pipes: @:

Delete the default CLI pipe commands.

Return value: XORP_OK on success, otherwise XORP_ERROR.

const vector<string>& CliCommand::global_name ( ) const [inline]

Get the global name of this command (i.e., the full name starting from the root).

Returns:
the global (full) name of this command.
bool CliCommand::has_type_match_cb ( ) const

Test if there is a callback for type matching.

Returns:
true if there is a callback for type matching, otherwise false.
bool CliCommand::is_argument_expected ( ) const [inline]

Test if the command expects an argument.

Returns:
true if the command expects an argument, otherwise false.
bool CliCommand::is_command_argument ( ) const [inline]

Test if the command actually represents a command argument.

Returns:
true if the command actually represents a command argument.
const string& CliCommand::server_name ( ) const [inline]

Get the server (i.e., processor) name for this command.

Returns:
the server name for this command.
void CliCommand::set_allow_cd ( bool  v,
const string &  init_cd_prompt 
)

Enable/disable whether this command allows "change directory" to it.

Parameters:
vif true, enable "change directory", otherwise disable it.
init_cd_promptif v is true, the CLI prompt to display when "cd" to this command. If an empty string, the CLI prompt will not be changed.
void CliCommand::set_can_pipe ( bool  v) [inline]

Set whether the output of this command can be piped.

Parameters:
vif true, then the the output of this command can be piped.
void CliCommand::set_cli_interrupt_callback ( const CLI_INTERRUPT_CALLBACK &  v) [inline]

Set the callback for command interrupt.

Parameters:
vthe callback for command processing.
void CliCommand::set_cli_process_callback ( const CLI_PROCESS_CALLBACK &  v) [inline]

Set the callback for command processing.

Parameters:
vthe callback for command processing.
void CliCommand::set_default_nomore_mode ( bool  v) [inline]

Set the default paging mode.

Parameters:
vif true, then "no-more" (i.e., unpaged) is the default output mode.
void CliCommand::set_dynamic_children_callback ( DYNAMIC_CHILDREN_CALLBACK  v)

Set the callback for dynamic generation of children commands.

Parameters:
vthe callback for dynamic generation of children commands.
void CliCommand::set_dynamic_interrupt_callback ( const CLI_INTERRUPT_CALLBACK &  v) [inline]

Set the callback for command interrupt for a dynamically generated child command.

Parameters:
vthe callback for command processing.
void CliCommand::set_dynamic_process_callback ( const CLI_PROCESS_CALLBACK &  v) [inline]

Set the callback for command processing for a dynamically generated child command.

Parameters:
vthe callback for command processing.
void CliCommand::set_global_name ( const vector< string > &  v) [inline]

Set the global name for this command.

Parameters:
vthe global name value to set.
void CliCommand::set_is_argument_expected ( bool  v) [inline]

Set a flag whether the command expects an argument.

Parameters:
vtrue if the command expectes an argument, otherwise false.
void CliCommand::set_is_command_argument ( bool  v) [inline]

Set a flag whether the command actually represents a command argument.

Parameters:
vtrue if the command represents a command argument, otherwise false.
void CliCommand::set_server_name ( const string &  v) [inline]

Set the server (i.e., processor) name for this command.

Parameters:
vthe server name value to set.
void CliCommand::set_type_match_cb ( const TypeMatchCb &  cb) [inline]

Set the callback for type matching.

Parameters:
cbthe callback for type matching.
const TypeMatchCb& CliCommand::type_match_cb ( ) const [inline]

Get the callback for type matching.

Returns:
the callback for type matching.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations