【PARAM usage】Can I write a PARAM tag that do nothing ?

20 views
Skip to first unread message

Shawn Qiu

unread,
Oct 12, 2021, 11:58:23 PM10/12/21
to klish-dev
The question is that I want to convert some commands like below to xml: 
cmd  [ < ipv4 | ipv6 >  [ unicast | multicast | vpn | labeled-unicast | flowspec ] ]
It seem like I need to write:
COMMAND  cmd
        PARAM  mode="switch"  optional="true"
                PARAM  ipv4  mode="subcommand"
                        PARAM  mode="switch"  optional="true"
                                PARAM  unicast  mode="subcommand"
                                PARAM  multicast  mode="subcommand"
                                PARAM  vpn  mode="subcommand"
                                PARAM  labeled-unicast  mode="subcommand"
                                PARAM  flowspec  mode="subcommand"
                PARAM  ipv6  mode="subcommand"
                        PARAM  mode="switch"  optional="true"
                                PARAM  unicast  mode="subcommand"
                                PARAM  multicast  mode="subcommand"
                                PARAM  vpn  mode="subcommand"
                                PARAM  labeled-unicast  mode="subcommand"
                                PARAM  flowspec  mode="subcommand"
But I would like to write:
COMMAND  cmd
        PARAM  nop  optional="true"
                PARAM  mode="switch"
                        PARAM  ipv4  mode="subcommand"
                        PARAM  ipv6  mode="subcommand"
                PARAM  mode="switch"  optional="true"
                        PARAM  unicast  mode="subcommand"
                        PARAM  multicast  mode="subcommand"
                        PARAM  vpn  mode="subcommand"
                        PARAM  labeled-unicast  mode="subcommand"
                        PARAM  flowspec  mode="subcommand"
PARAM nop is used to control optional of its child params but user in CLI doesn't need to enter value for it. 
I found that somebody had created an issue about this in google code. It's Issue 82.
So is that feature available?

Looking forward to your reply,
Thank you

Serj Kalichev

unread,
Oct 13, 2021, 4:26:09 PM10/13/21
to klis...@googlegroups.com
Such feature is not available.
You can write something like that:

COMMAND  cmd
            PARAM  name="s1" mode="switch" optional="true"
                    PARAM  ipv4  mode="subcommand"
                    PARAM  ipv6  mode="subcommand"
            PARAM  mode="switch"  optional="true" test='"x${s1}" != "x"'
                    PARAM  unicast  mode="subcommand"
                    PARAM  multicast  mode="subcommand"
                    PARAM  vpn  mode="subcommand"
                    PARAM  labeled-unicast  mode="subcommand"
                    PARAM  flowspec  mode="subcommand"

Note "test=..." and "optional" with first switch


13.10.2021 06:58, 'Shawn Qiu' via klish-dev пишет:
--
You received this message because you are subscribed to the Google Groups "klish-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/klish-dev/91df0ae6-ba16-4789-a6fd-db0b8e5f7a63n%40googlegroups.com.


Shawn Qiu

unread,
Oct 13, 2021, 10:38:22 PM10/13/21
to klish-dev
It works and it's just what I need! Thank you very much!!

In fact I had tried that but I made a mistake. I wrote test=“-n ${switch_param_name}” but it didn't work as my expection. 
The correct syntax is test='-n "${switch_param_name}"'. Never forget to use a pair of quotation marks while testing a string!

Thanks again!

Serj Kalichev

unread,
Oct 14, 2021, 3:13:10 PM10/14/21
to klis...@googlegroups.com
I'm not sure but may be something like test='"${switch_name}"' will work too.


14.10.2021 05:38, 'Shawn Qiu' via klish-dev пишет:

Shawn Qiu

unread,
Oct 15, 2021, 2:05:47 AM10/15/21
to klish-dev
Yes, my test show that the effect of using test='"${switch_name}"' and test='${switch_name}' are the same, and both of them could work.
But test='-n ${switch_name}' and test='-n "${switch_name}"' are different.

Reply all
Reply to author
Forward
0 new messages