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

CLI syntax help #22

Closed
sharmadeepak29 opened this issue Feb 21, 2019 · 6 comments
Closed

CLI syntax help #22

sharmadeepak29 opened this issue Feb 21, 2019 · 6 comments
Labels

Comments

@sharmadeepak29
Copy link

sharmadeepak29 commented Feb 21, 2019

Hello,
I am trying to write a cli using your cligen module. I am facing a issue.
Below is my syntax:-

aa
{
[bb]
[cc]
[dd];
}

now on cli prompt output:-
cli>aa bb cc dd --- valid output
cli>aa cc dd bb --- not a valid output

I am wondering why i am not able to give the second command.
Is there a restriction on order of parameters at the same level. If yes, I would like to have an order independent command processing. Can we have a syntax which will help in in achieving my goal.

when i do
cli> aa cc ?
it should show both
bb
dd

as help ouptut.

Thanks and Regards,
Deepak Sharma

@olofhagsand
Copy link
Member

Sharma,
your syntax can be written as:

  aa {
    [bb] [cc] [dd];
  }

Since the [bb][cc][dd] is in sequence, they must appear one after the other.
Valid strings are therefore: "aa", "aa bb", "aa bb cc", "aa bb cc dd", "aa bb dd", "aa cc", "aa cc dd", and "aa dd".
An alternative is:

  aa {
    [bb]; [cc]; [dd];
  }

where valid strings are "aa bb"; "aa cc" and "aa dd".

If you want a list, eg (*) or (+) they can not be implemented with this basic syntax. Instead you could use the tree operator '@', for example:

  a @list;
  treename="list";
  [bb] [cc] [dd] @list;

or, with a terminating condition:

  a @list;
  treename="list";
  [bb] [cc] [dd];{ 
          @list;
  }

@sharmadeepak29
Copy link
Author

sharmadeepak29 commented Feb 25, 2019

Hello Olof,

Thank you for your response.
However, there one issue with that, I can give the same parameter again and again in command.
I am looking for a CLI to be order independent.

  1. Can we have a CLI with no dependence on order if the parameters are at the same level?
    for example:-
    aa{
    [bb]
    [cc]
    [dd];
    }

Possible help:-
cli> aa bb ?

cc
dd

cli> aa cc ?

bb
dd

cli> aa dd ?

bb
cc

  1. Is there a way to display only those parameters which have not been used in the command till now?

And if there is no such syntax possible would you like to take it as an enhancement or let me know how I can enhance the code to cater to my requirements. I would love to contribute to your work,

@olofhagsand
Copy link
Member

No, not in a straight-forward way. I dont know how to do that in a BNF or context-free grammar or regexp in general? Ie, from a set of words accept all combinations of them occuring exactly once. The closest I can think of is members of a "set".
You are welcome to contribute but it would have to use some new syntax. Preferably if you can find some notation from some other formal language or tool.

The only solution I can find is something like:

aa {
  bb{
    cc dd;
    dd cc;
    }
  cc{
    bb dd;
    dd bb;
  }
  dd{
    bb cc;
    cc bb;
  }
}

which is the same as:

aa {
  bb (cc dd|dd cc);
  cc (bb dd|dd bb);
  dd (bb cc|cc bb);
}

or:

aa (bb (cc dd|dd cc) | cc (bb dd|dd bb) |  dd (bb cc|cc bb));

I am a little curious: what is the use-case for this?

@olofhagsand
Copy link
Member

New "sets" feature added, see:
ed1997a

Example: aa @{ bb; cc; dd; }

@gopiKrishnaPuligundla
Copy link

Hi Olof ,
is there a complete guide on different options cligen provides and how to use it , what ever pdf available in git repository doesn't discuss all available options

@olofhagsand
Copy link
Member

CLIgen has several options that can be set programmatically using the API here:
https://github.com/clicon/cligen/blob/master/cligen_handle.h
Most of them are not documented in the cligen-tutorial pdf.
The easiest would be to to add them there.
Thanks for pointing that out.

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

3 participants