command-line-interfaceyang

Extending yang with help prompts for cli


I am writing a new CLI and I am considering using yang as a data definition language. It has almost everything I need: mandatory/optionals, types, derived types, acceptable ranges, descriptions and a ton of existing modules.

However, I want to provide short help prompts: type '?' and see possible values for the next field with a short help (say 60 chars max). And there are no short prompts in .yang structure as far as I know.

How one would add short prompt information to a .yang file? Have a companion file containing only short prompts? Extend .yang format? Embed this information in .yang comments?

I am sure I am not the first person doing it, what is the recommended practice? I suspect the answer is 'companion file' because it will work with existing .yang files.


Solution

  • The description statement is used to provide information for the module reader. If you want to provide a more user friendly text you can define your own statement. YANG supports a extension statement for this purpose.

    Define it:

    module my-extensions {
           ...
    
       extension help {
           description "Takes as argument a help-text string.";
           argument "text";
       }
    }
    

    Use it:

    module example {
       import my-extensions {
           prefix "myext";
       }
           
       container example {
           myext:help "This is an example container";
       }
    }