Search code examples
cxmlclish

klish - dynamic variables and completion


I am writing an xml file in klish. I want to know how can we auto complete an parameter by pressing tab button in klish xml files. For E.g. I want user to enter either enable or disable on klish command line but if user press 'e' and tab then automatically enable should be completed or if user presses 'd' and tab then automatically disable should come. I am receiving these parameter on klish command line by user.

And also can we define macros in klish xml files so that i can use that macro in klish ACTION tag to pass that macro value as a parameter to my c file

My XML code is like this :-

<?xml version="1.0" encoding="UTF-8"?>
<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
  http://clish.sourceforge.net/XMLSchema/clish.xsd">
    <!--=======================================================-->
        <COMMAND name="show"
        help="some utility commands for show"/>
    <COMMAND name="show connection"
    help="Show the connection">
        <DETAIL>
           connection status
        </DETAIL>
    <ACTION>c_file.c 1</ACTION>
    </COMMAND>
<COMMAND name="show debugcount"
     help="It will show enable core">
     <DETAIL>
    Enable core.
      </DETAIL>
     <PARAM name="module-name"
      help="Specify the module name i.e. enable or disable"
      ptype="STRING"/>
     <ACTION>c_file.c 3 ${module-name}</ACTION>
</COMMAND>

As I mentioned that I want auto complete of a statement so the parametere i.e.

${modulename}

will be either enable or disable so I want if user press e and tab then automatically enable should come or if user press d and tab then automatically disable should be come.

And about macros as you can see in tag I am passing value i.e.

<ACTION>c_file.c 1</ACTION> 

to my c file but instead of value I want to use some variable name or macro so it would be something like

<ACTION>c_file ${var} ${modulename}</ACTION>

where $var=1


Solution

  • After lot of research finally I successfully implemented auto completion of command. Like in my example I want user to enter enable or disable in command line. This can be achieved by the following xml file. Just we had to use VAR tag in xml file and same for macros.

    <?xml version="1.0" encoding="UTF-8"?>
    <CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
    http://clish.sourceforge.net/XMLSchema/clish.xsd">
    <!--=======================================================-->
    
    <COMMAND name="show"
             help="some utility commands for show"/>
    
    <COMMAND name="show connection"
             help="Show the connection">
    <DETAIL>
         connection status
    </DETAIL>
    <ACTION>c_file.c 1</ACTION>
    </COMMAND>
    <COMMAND name="show debugcount"
     help="It will show enable core">
    <DETAIL>
    Enable core.
    </DETAIL>
    <PARAM name="module-name"
           help="Specify the module name i.e. enable or disable"
           ptype="STRING"
           completion="${third_par}"/>
    
     <ACTION>c_file.c 3 ${module-name}</ACTION>
    
    <VAR name="third_par" help="enable/disable" value="enable disable"/>
     </COMMAND>