How can I know which mode the command is executed when run a CLI callback function

Hi,

I have a capi callback function defined in clispec to extend “show” commands.

But “show” commands can run in exec mode and config mode by “do show”.

How can I know which mode it is in when I run the show command?

BR,
Harry Huang

Hi,
In the C-style CLI in config mode, clispec <configureMode>, if you put a “do” front of a command you are then running the command in oper mode, clispec <operationalMode>.

Hi Cohult,

In the completion callback, how can I tell the command is executed in operational mode or config mode?

You can for example do something like:

<clispec xmlns="http://tail-f.com/ns/clispec/1.0" style="c">
  <operationalMode>
    <cmd name="echo">
      <info>Echo</info>
      <help>Oper mode echo.</help>
      <callback>
        <exec>
          <osCommand>echo</osCommand>
          <args>oper mode</args>          
        </exec>
      </callback>
    </cmd>
  <configureMode>
    <cmd name="echo">
      <info>Echo</info>
      <help>Config mode echo.</help>
      <callback>
        <exec>
          <osCommand>echo</osCommand>
          <args>config mode</args>
        </exec>
      </callback>
    </cmd>
  </configureMode>
</clispec>

Quick demo:

$ confd_cli -u admin -C
admin connected from 127.0.0.1
# echo
oper mode
# config
Entering configuration mode terminal
(config)# echo   
config mode
(config)# do echo
oper mode

Thank cohult.

My question is that when I am using a completion callback, how can I know the completion callback is executed in config mode or in operational mode?

The completion callback definition is like below.
int (*completion)(struct confd_user_info *uinfo,
int cli_style, char *token, int completion_char,
confd_hkeypath_t *kp,
char *cmdpath, char *cmdparam_id,
struct confd_qname *simpleType, char *extra);

Perhaps you can make use of the the “id” attribute passed to your callback through the “char * cmdparam_id”?