1

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

vivek
  • 467
  • 2
  • 6
  • 18
  • What have you done so far? If you have a code, please show it to us so we can help you. Learn [how to ask a good question.](https://stackoverflow.com/help/how-to-ask) – Manav Dubey Apr 23 '17 at 17:35
  • @naru sin I added my XML files. Please help if you have any idea about this – vivek Apr 24 '17 at 04:22

3 Answers3

2

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>
vivek
  • 467
  • 2
  • 6
  • 18
1

About completion. There are several ways to implement it. The first way is something like this:

<PARAM name="module-name"
   help="Specify the module name i.e. enable or disable"
   ptype="STRING"
   completion="enable disable"/>

It's simple but not strict i.e. user can type something else than "enable/disable".

The second way is PTYPE with method="select":

<PTYPE name="BOOL" method="select" pattern="true(1) false(0)" help="Boolean choice"/>

This way is strict. Autocompletion will show "true/false" but user will get corresponding PARAM with values "1/0" in ACTION. But you can use pattern="true(true) false(false)" to get "true" or "false" in ACTION.

The third way is switch:

<PARAM name="choose" help="switch example" mode="switch" ptype="SWITCH">
    <PARAM name="enable" help="Enable" ptype="SUBCOMMAND" mode="subcommand"/>
    <PARAM name="disable" help="Disable" ptype="SUBCOMMAND" mode="subcommand"/>
</PARAM>

It's strict. The user must choose (enter) only one of PARAMs inside "switch" PARAM.

About VARs... The VARs in klish is global. So it can appear without COMMAND tag or VIEW tag. Put it on the same level as "VIEW" tag.

  • Thanks @Serj, Actually initially when I started with the klish I have no idea on this and I posted this query in google group of klish also but no one replied but some how when I spent time on the manual of klish I come to know this way....so i posted this answer on stack overflow....Now after your post I have learn two more ways for accomplish this thing.... Thanks once again and Welcome to SO – vivek Jan 16 '18 at 06:20
  • @Serj Do you know why I can tab to auto complete all command names but hitting enter will auto complete some commands and it fails for other commands and says "illegal parameter"? – Paul Apr 15 '19 at 16:29
0

I am not sure if the above XML is well-formed. It seems that in the current clish.xsd schema the <VAR> element is no longer valid to be under the <COMMAND> element. In fact, the <VAR> element has no valid place at all.

To verify: xmllint -schema /path/to/latest/clish.xsd --noout /path/to/your/file.xml

You will notice that the presence of the <VAR> will invalidate the XML against the schema.

Below is the <COMMAND> element schema:

  <xs:complexType name="command_t">
    <xs:sequence>
        <xs:element ref="DETAIL" minOccurs="0"/>
        <xs:element ref="PARAM" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="CONFIG" minOccurs="0"/>
        <xs:element ref="ACTION" minOccurs="0"/>
    </xs:sequence>
    <xs:attributeGroup ref="menu_item_g"/>
    <xs:attribute name="ref" type="xs:string" use="optional"/>
    <xs:attribute name="view" type="xs:string" use="optional"/>
    <xs:attribute name="viewid" type="xs:string" use="optional"/>
    <xs:attribute name="access" type="xs:string" use="optional"/>
    <xs:attribute name="args" type="xs:string" use="optional"/>
    <xs:attribute name="args_help" type="xs:string" use="optional"/>
    <xs:attribute name="escape_chars" type="xs:string"   
use="optional"/>
    <xs:attribute name="lock" type="bool_t" use="optional" 
default="true"/>
    <xs:attribute name="interrupt" type="bool_t" use="optional" 
default="false"/>
</xs:complexType>

Basically, specifying that inside COMMAND should be in order the following:

  • DETAIL
  • PARAM
  • CONFIG
  • ACTION

So if you place DETAIL after PARAM, it is invalid against the schema. I am referring to the following clish.xsd schema version in klish git repo:

Author: Serj Kalichev <serj.kalichev@gmail.com>
Date:   Fri Dec 15 18:03:53 2017 +0300

Version 2.1.4
daparic
  • 3,794
  • 2
  • 36
  • 38