Package: helpner
helpnerDetect the content of CLI help messages:warning:
This library is a work in progress and aproof of concept.Helpner can be used to explore the positions ofcommands (CMD),arguments (ARG)andoptions (OPT)from Command Line Interface program help's messages, usingNamed Entity Recognition (NER).:pencil: ExamplesLets see some examples before reading on.flitinstall--help|helpnerhighlightmake--help|helpnerhighlightThese images are svg screen captures of running thehelpner highlightagainst two help messages,flit installandmakein this case.Some notes:The model which powershelpneris anstatistical model, meaning the final output (in the case of the programs shown in the figures) is a prediction which may not be most accurate, seespaCy modelsfor more info on this point.The model cannot be better than the data it was built on, and the data which powers the model, is by no means complete or perfect. More info on the data generator can be seen in the corresponding repositorycli-help-maker.With this in mind, lets keep reading :smile:...why this:question:Why not? While reading throughdocopt-ngI thought if it would be possible to detect the components [^1] of a command line interface program and extract them. It turned out to be a fun project. It isn't the best approach for the task, but it allowed to explore a different application of AI, this time from the from and for the console (a nice mix ofspaCyandrich!).[^1]: Seedocoptfor a better explanation of the components.👩‍💻 Usagehelpner's CLI is composed of 3 subcommands:helpner highlight: Main command, throw some color :rainbow: to the help messages withrich!Pipe the help message from the CLI program stdin to the program, and it will print back the original message with the entities detected highlighted and wrapped in a panel. Thestyleapplied can be modified for each entity using the options:❯make--help|helpnerhighlight--style-opt'red on white'--style-arg'bold yellow'--style-cmd'underline blue'It can also capture console content and write it to an svg file thanks to rich:❯make--help|helpnerhighlight--style-opt'red on white'--style-arg'bold yellow'--style-cmd'underline blue'--save-svg--svg-filenamemake-other-help.svghelpner parse: It parses the help message, shows the content detected by the model. The keys correspond to the content found, and the values are a tuple with the entity detected and the positions in the string.The content can be either shown as JSON (it may come handy to dump the content to a file):make--help|helpnerparse--json>make-helpner.jsonOr as a Python's dict:❯make--help|helpnerparse--no-json{make:('CMD',7,11),[target]...:('ARG',22,34),-b,-m:('OPT',46,52),-B,--always-make:('OPT',103,120),-CDIRECTORY,--directory=DIRECTORY:('OPT',167,202),-d:('OPT',278,280),--debug[=FLAGS]:('OPT',345,360),-e,--environment-overrides:('OPT',421,448),--eval=STRING:('OPT',523,536),-fFILE,--file=FILE,--makefile=FILE:('OPT',594,631),-h,--help:('OPT',689,699),-i,--ignore-errors:('OPT',748,767),-IDIRECTORY,--include-dir=DIRECTORY:('OPT',806,843),-j[N]:('OPT',917,923),,--jobs[=N]:('ARG',923,935),-k,--keep-going:('OPT',996,1012),-l[N]:('OPT',1070,1076),-L,--check-symlink-times:('OPT',1195,1220),-n,--just-print,--dry-run,--recon:('OPT',1275,1311),recipe:('CMD',1365,1371),-oFILE,--old-file=FILE,--assume-old=FILE:('OPT',1392,1435),-O[TYPE],--output-sync[=TYPE]:('OPT',1518,1548),-p,--print-data-base:('OPT',1626,1647),-q,--question:('OPT',1688,1702),-r,--no-builtin-rules:('OPT',1765,1787),-R,--no-builtin-variables:('OPT',1832,1858),-s,--silent,--quiet:('OPT',1902,1923),-S,--no-keep-going,--stop:('OPT',1952,1979),-t,--touch:('OPT',2026,2037),--trace:('OPT',2096,2103),-v,--version:('OPT',2153,2166),-w,--print-directory:('OPT',2226,2247),--no-print-directory:('OPT',2285,2305),-WFILE,--what-if=FILE,--new-file=FILE,--assume-new=FILE:('OPT',2365,2424),--warn-undefined-variables:('OPT',2493,2519)}andhelpner download, which will be explained in theInstallationsection.More examples can be seen inassetsfolder, and better yet, test what you want by yourself. Just keep in mind... The model is far from perfect, the data generator is still a work in progress.🔧 InstallationYou can installhelpnerviapip(almost ready):pipinstallhelpnerThe program still needs a model to make the predictions, which can be obtained similar to how you would do it withspaCy's models[^2].[^2]: To see how spaCy'sdownloadcommand works visit:spacy download.So in a second step, you can run the following command:helpnerdownloadThis command will (pip) install the model fromgithub releases, which facilitates two things:The model can be updated independently fromhelpner, given that both things can evolve at different speedsSimplifies finding the most updated model available (which should be the only one relevant anyway).In case the command fails and it couldn't install the package, it will point to the models directly.:bulb: How does it work?The following sketch[^3] shows the parts involved in the final program:[^3]: Visitexcalidrawif you don't know it, it's amazing.cli-help-maker: A library that allows to generate help messages for dummy command line programs, with annotations of the three entities (CMD,ARGandOPT).helpner-core: Thespacy projectwhich allows to smoothly manage the end-to-end workflow. More project examples can be found in explosion'sprojectsrepository.releases: Releases ofhelpner-coremodels, uploaded as python packages installable viapip install.helpner: The entrypoint to the model via command line interface.