palaniyappanBala / klish

Automatically exported from code.google.com/p/klish
Other
0 stars 0 forks source link

Conditional optional parameter #116

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'd like to be able to have a conditional optional parameter, or at least a 
dynamic completion that automatically fills in the rest of the parameter.

<VIEW name="configure-view">
  <COMMAND name="route"
           help="Select a route to configure"
           view="configure-route-view"
           viewid="route=${route};pattern=${pattern}">
    <PARAM name="route"
           help="Name of the route you would like to configure"
           ptype="STRING"
           completion="${POSSIBLE_ROUTE}"/>
    <PARAM name="pattern"
           help="Route pattern"
           ptype="STRING"/>
  </COMMAND>
</VIEW>

If the route name already exists then I don't need a pattern since I'll just 
use the one that exists. If the route name does not exist then I'll need a 
pattern. Is there any way to have a conditional optional parameter? I already 
have the dynamic command completion but if I return the route name and the 
pattern it just gets returned as two separate completions for the route name.

What version of the product are you using? On what operating system?
1.5.4 - Debian

Original issue reported on code.google.com by zaka...@gmail.com on 30 Apr 2012 at 2:09

GoogleCodeExporter commented 8 years ago
You can use field "test" to get conditional PARAM. If test is true the PARAM is 
visible else it will be invisible.

Example <PARAM name="kkk" ... test="${MY_VAR} = 2"/>
The condition is like a shell "test" utility.
It can contain user defined variables.
It's not obvious how to implement condition in your case. But there is a hack. 
If the user defined variable is "dynamic" it will see the other PARAMs values 
because it will executed in the current command context.
So you can implement the user defined var and the return value of this var can 
depends on the name (and existence) of your route. But note it's a hack.

Original comment by serj.kalichev@gmail.com on 30 Apr 2012 at 6:23

GoogleCodeExporter commented 8 years ago
<VIEW name="configure-view">
  <COMMAND name="route"
           help="Select a route to configure"
           view="configure-route-view"
           viewid="route=${route};pattern=${pattern};trunk_group_id=${trunk_group_id}">
    <PARAM name="route"
           help="Name of the route you would like to configure"
           ptype="STRING"
           completion="${POSSIBLE_ROUTE}"/>
    <PARAM name="trunk_group_id"
           help="Route trunk group ID"
           ptype="UINT"
           completion="${POSSIBLE_TRUNK_GROUP_ID}"/>
    <PARAM name="pattern"
           help="Route pattern"
           ptype="STRING"
           test="${POSSIBLE_ROUTE}"
           completion="${POSSIBLE_PATTERN}"/>
  </COMMAND>
</VIEW>

Okay so I've got that now but it's the opposite of what I want, if the route 
exists it requires a pattern, if the route doesn't exist it doesn't require a 
pattern. If I do test="!${POSSIBLE_ROUTE}" then it requires the pattern whether 
the route exists or not. Same thing happens when I use 
test="${POSSIBLE_PATTERN}" or test="${POSSIBLE_PATTERN} != ''".

Original comment by zaka...@gmail.com on 30 Apr 2012 at 7:33

GoogleCodeExporter commented 8 years ago
The value of variable is not expression itself. The value of variable is output 
of variables's code. Like a var=`ls`. The variable can generate different 
output depends on some conditions.

<... test='"${CHECK_ROUTE}" = "exist"'/>

Original comment by serj.kalichev@gmail.com on 2 May 2012 at 7:04

GoogleCodeExporter commented 8 years ago
Not sure that I understand. I want to only require a pattern if 
${POSSIBLE_PATTERN} returns "" so I tried 

test="${POSSIBLE_PATTERN} != ''"

but that doesn't work it asks for a pattern when ${POSSIBLE_PATTERN} returns 
something and does not ask for a pattern when ${POSSIBLE_PATTERN} returns 
nothing (the opposite of what I want.)

If I try the opposite -

test="${POSSIBLE_PATTERN} = ''"

it asks for a pattern for both. So I'm really confused as to what it's checking 
against. Does it try to get the value of ${POSSIBLE_PATTERN} first? Does it run 
everything using test in the command line? ${POSSIBLE_PATTERN} is set by a Perl 
script so does that affect anything?

<VAR name="POSSIBLE_PATTERN"
     help="Displays route pattern"
     dynamic="true">

  <ACTION>
    helper.pl exists --table=asterisk.v_routes --keycol=route_name --val="${route}%" --retcol=pattern --retempty="1"
  </ACTION>
</VAR>

Original comment by zaka...@gmail.com on 2 May 2012 at 5:03

GoogleCodeExporter commented 8 years ago
Okay I got it to work by making my script return 'empty' when there are no 
matches and using this for the param -

<PARAM name="pattern"
       help="Route pattern"
       ptype="STRING"
       test='${POSSIBLE_PATTERN} = "empty"'
       completion="${POSSIBLE_PATTERN}"/>

The only problem is when my script returns 'empty' if I tab complete it'll 
actually say 'empty'.

Original comment by zaka...@gmail.com on 2 May 2012 at 6:54

GoogleCodeExporter commented 8 years ago
Ah okay fixed that too, I made a new variable for testing that returns empty if 
it needs to, and the completion variable returns nothing when there's nothing 
to complete, thank you very much.

    <PARAM name="pattern"
           help="Route pattern"
           ptype="STRING"
           test='${ROUTE_EXISTS} = "empty"'
           completion="${POSSIBLE_PATTERN}"/>

Original comment by zaka...@gmail.com on 2 May 2012 at 7:07