Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto completion does not work for strings including space. Seen only when autocompletion is strict and is via customary callback in .cli file #221

Closed
DeekshaBhandary opened this issue May 11, 2021 · 5 comments
Labels

Comments

@DeekshaBhandary
Copy link

Case 1:

supervisor@apr29: cfg> show bgp peer instance    
  "i1 space"            Peer information for an instance                                                                                      
  i1                    Peer information for an instance                                                                                      
supervisor@apr29: cfg> show bgp peer instance i1 
  <cr>
  detail                Detailed peer information                                                                                             
supervisor@apr29: cfg> show bgp peer instance "i1 space" <PRESS ?>   <----expand options not seen
supervisor@apr29: cfg> show bgp peer instance "i1 space" 
CLI syntax error: "show bgp peer instance "i1 space"": Unknown command          
supervisor@apr29: cfg> set instance            
  "i1 space"            An operator-assigned unique name for the network instance                                                             
  i1                    An operator-assigned unique name for the network instance                                                             
  <name>                An operator-assigned unique name for the network instance                                                             
supervisor@apr29: cfg> 

Case 2:

supervisor@apr29: cfg>set instance i1 
  <cr>
  address-family        Instance address family related configurations                                                                        
  ipv4-router-id        IPv4 router id of the routing instance                                                                                
  protocol              Protocol configuration                                                                                                
  route-distinguisher   VPN Route Distinguisher. Format: {as_number | ipv4_address}:rd_identifier                                             
  static                Configuration data for static route configuration table                                                               
  tcp                   TCP configuration                                                                                                     
supervisor@apr29: cfg> set instance "i1 space"             <----works for the CLI tree
  <cr>
  address-family        Instance address family related configurations                                                                        
  ipv4-router-id        IPv4 router id of the routing instance                                                                                
  protocol              Protocol configuration                                                                                                
  route-distinguisher   VPN Route Distinguisher. Format: {as_number | ipv4_address}:rd_identifier                                             
  static                Configuration data for static route configuration table                                                               
  tcp                   TCP configuration                                                                                                     
supervisor@apr29: cfg> set instance "i1 space" 

As far as my analysis i found the issue in cligen_str2cvv . In the tokens that are generated quotes are not included. Adding them using escape character solves the issue. i have done the code changes and tested it.
The reason it works in the case 2 is because for strings with space, in match_vec it gets matched against the generic node
and not the specified value

can you please confirm this?

@olofhagsand
Copy link
Member

I need some more info on the show command:
supervisor@apr29: cfg> show bgp peer instance "i1 space" <PRESS ?> <----expand options not seen
which cli callback is this: cli_auto_show() or cli_show_auto(), can you please provide the cligen line of that command?

@DeekshaBhandary
Copy link
Author

DeekshaBhandary commented May 13, 2021

The show command syntax is derived from .cli file:
file bgp.cli :

show("Show a particular state of the system") {
    bgp("BGP protocol information") {
                peer("Peer information"), rtb_cli_exec("bgp", "show_bgp_peer"); {
                (<peer_name:string expand_func("bgp","bgp_peer_host_expander")>("Peer name")), exec_func("bgp", "show_bgp_peer_host"); {
                detail("Detailed peer information"), exec_func("bgp", "show_bgp_peer_detail"); 
			}
		}
	}
}

expand_func and exec_func are C functions that call other functions to achieve expansion and to display the output (specified as 2nd argument. the functions called by expand_func and exec_func are written in python).

container bgp {
     ..
	 ..
     uses bgp-peer;	 
}
	 
grouping bgp-peer {
	    list interface {
		    key "name";
			leaf name {
			}
			uses bgp-pg-name;
	}
}
			
grouping bgp-pg-name {
        description "BGP peer group name";
        leaf peer-group {
            type string;
		}
}

@olofhagsand
Copy link
Member

I cannot re-create it in my example code.
It may very well be errors in the clixon code, but in the efforts I made to recreate it I failed.
It may also be some problem in your code.
Working example using clixon main example:

olof@alarik /> set interfaces interface "a b" type ex:eth
olof@alarik /> show auto interfaces interface <PRESS ?> <---------
  "a b"                 The name of the interface.                                                   
  <name>                The name of the interface.                                                   
olof@alarik /> show auto interfaces interface "a<PRESS TAB>  <----
olof@alarik /> show auto interfaces interface "a b"
 xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"<interface>
   <name>a b</name>
   <type>ex:eth</type>
   <enabled>true</enabled>
</interface>
olof@alarik /> 

Can you recreate the problem using the main example?

@olofhagsand
Copy link
Member

This may do it?

diff --git a/cligen_match.c b/cligen_match.c
index 2ec6aeb..241e808 100644
--- a/cligen_match.c
+++ b/cligen_match.c
@@ -158,7 +158,10 @@ match_object(cligen_handle h,
       if (str == NULL)
          match++;
       else{
-         match = (strncmp(co->co_command, str, len) == 0);
+         if (*co->co_command == '\"') /* escaped */
+             match = (strncmp(co->co_command+1, str, len) == 0);
+         else
+             match = (strncmp(co->co_command, str, len) == 0);
          if (exact)
              *exact = strlen(co->co_command) == len;
          if (match == 0 && reason){

olofhagsand added a commit to clicon/cligen that referenced this issue May 18, 2021
…Seen only when autocompletion is strict and is via customary callback in .cli file #221](clicon/clixon#221)

* Removed expandvar from all match functions
@olofhagsand
Copy link
Member

Should work now. Please verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants