Giter Club home page Giter Club logo

explainshell's Introduction

#explainshell.com - match command-line arguments to their help text

explainshell is a tool (with a web interface) capable of parsing man pages, extracting options and explain a given command-line by matching each argument to the relevant help text in the man page.

How?

explainshell is built from the following components:

  1. man page reader which converts a given man page from raw format to html (manpage.py)
  2. classifier which goes through every paragraph in the man page and classifies it as contains options or not (algo/classifier.py)
  3. an options extractor that scans classified paragraphs and looks for options (options.py)
  4. a storage backend that saves processed man pages to mongodb (store.py)
  5. a (recursive) parser that supports a subset of shell syntax, such as redirections, pipelines, lists, compound commands (notably missing is support for command substitutions) (parser.py)

When querying explainshell, it:

  1. parses the query into an AST
  2. visits interesting nodes in the AST, such as:
    • command nodes - these nodes represent a simple command
    • shell related nodes - these nodes represent something the shell interprets such as '|', '&&'
  3. for every command node we check if we know how to explain the current program, and then go through the rest of the tokens, trying to match each one to the list of known options
  4. returns a list of matches that are rendered with Flask

TODO file

Missing man pages

Right now explainshell.com contains the entire archive of Ubuntu. It's not possible to directly add a missing man page to the live site (it might be in the future). Instead, submit a link here and I'll add it.

Running explainshell locally

To setup a working environment that lets you run the web interface locally, you'll need to:

$ pip install -r requirements.txt

# load classifier data, needs a mongodb
$ mongorestore dump/explainshell && mongorestore -d explainshell_tests dump/explainshell
$ make tests
.....................................................
----------------------------------------------------------------------
Ran 53 tests in 2.847s

OK

Processing a man page

Use the manager to parse and save a gzipped man page in raw format:

$ python explainshell/manager.py --log info echo
INFO:explainshell.store:creating store, db = 'explainshell_tests', host = 'mongodb://localhost'
INFO:explainshell.algo.classifier:train on 994 instances
INFO:explainshell.manager:handling manpage echo (from /tmp/es/manpages/1/echo.1.gz)
INFO:explainshell.store:looking up manpage in mapping with src 'echo'
INFO:explainshell.manpage:executing '/tmp/es/tools/w3mman2html.cgi local=%2Ftmp%2Fes%2Fmanpages%2F1%2Fecho.1.gz'
INFO:explainshell.algo.classifier:classified <paragraph 3, DESCRIPTION: '-n     do not output the trailing newlin'> (0.991381) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph 4, DESCRIPTION: '-e     enable interpretation of backslash escape'> (0.996904) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph 5, DESCRIPTION: '-E     disable interpretation of backslash escapes (default'> (0.998640) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph 6, DESCRIPTION: '--help display this help and exi'> (0.999215) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph 7, DESCRIPTION: '--version'> (0.999993) as an option paragraph
INFO:explainshell.store:inserting mapping (alias) echo -> echo (52207a1fa9b52e42fb59df36) with score 10
successfully added echo

Start up a local web server:

$ make serve
python runserver.py
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

explainshell's People

Contributors

idank avatar bgreenlee avatar sondove avatar

Watchers

lhuaiy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.