1
1
# [ explainshell.com] ( http://www.explainshell.com ) - match command-line arguments to their help text
2
2
3
3
explainshell is a tool (with a web interface) capable of parsing man pages, extracting options and
4
- explain a given command-line by matching each argument to the relevant help text in the man page.
4
+ explaining a given command-line by matching each argument to the relevant help text in the man page.
5
5
6
6
## How?
7
7
@@ -19,9 +19,9 @@ When querying explainshell, it:
19
19
20
20
1 . parses the query into an AST
21
21
2 . visits interesting nodes in the AST, such as:
22
- - command nodes - these nodes represent a simple command
23
- - shell related nodes - these nodes represent something the shell
24
- interprets such as '|', '&&'
22
+ - command nodes - these nodes represent a simple command
23
+ - shell related nodes - these nodes represent something the shell
24
+ interprets such as '|', '&&'
25
25
3 . for every command node we check if we know how to explain the current program,
26
26
and then go through the rest of the tokens, trying to match each one to the
27
27
list of known options
@@ -40,23 +40,30 @@ Setup a working environment that lets you run the web interface locally using do
40
40
41
41
``` ShellSession
42
42
# download db dump
43
- $ curl -L -o /tmp/dump.gz https://github.com/idank/explainshell/releases/download/db-dump/dump.gz
43
+ curl -L -o /tmp/dump.gz https://github.com/idank/explainshell/releases/download/db-dump/dump.gz
44
44
45
45
# start containers, load man pages from dump
46
46
docker-compose build
47
47
docker-compose up
48
48
49
49
docker-compose exec -T db mongorestore --archive --gzip < /tmp/dump.gz
50
50
51
- # open http://localhost:5000
51
+ # run tests
52
+ docker-compose exec -T web make tests
53
+ ..SSSSSSSSS.....................................................................
54
+ ----------------------------------------------------------------------
55
+ Ran 80 tests in 0.041s
56
+
57
+ OK (SKIP=9)
58
+ # open http://localhost:5000 to view the ui
52
59
```
53
60
54
61
### Processing a man page
55
62
56
63
Use the manager to parse and save a gzipped man page in raw format:
57
64
58
65
``` ShellSession
59
- $ PYTHONPATH=. python explainshell/manager.py --log info manpages/1/ echo.1.gz
66
+ $ docker-compose exec -T web bash -c " PYTHONPATH=. python explainshell/manager.py --log info /usr/share/man/man1/ echo.1.gz"
60
67
INFO:explainshell.store:creating store, db = 'explainshell_tests', host = 'mongodb://localhost'
61
68
INFO:explainshell.algo.classifier:train on 994 instances
62
69
INFO:explainshell.manager:handling manpage echo (from /tmp/es/manpages/1/echo.1.gz)
@@ -71,43 +78,4 @@ INFO:explainshell.store:inserting mapping (alias) echo -> echo (52207a1fa9b52e42
71
78
successfully added echo
72
79
```
73
80
74
- ### Start up a local web server
75
-
76
- ``` ShellSession
77
- $ make serve
78
- python runserver.py
79
- * Running on http://127.0.0.1:5000/
80
- * Restarting with reloader
81
- ```
82
-
83
- ### Start up a local web server with docker
84
-
85
- ``` ShellSession
86
- # Build docker web and db containers
87
- $ docker-compose build
88
- $ docker-compose up
89
-
90
- # Copy dump over to container for than to import it.
91
- $ docker cp dump/ explainshell_db_1:/tmp/dump
92
-
93
- # Import classifiers
94
- $ docker exec explainshell_db_1 mongorestore /tmp/dump
95
-
96
- # Import a man page
97
- $ docker exec explainshell_web_1 bash -c " PYTHONPATH=. python explainshell/manager.py --log info /usr/share/man/man1/grep.1.gz"
98
- ...
99
- successfully added grep.1.gz
100
-
101
- # Open browser at port 5000
102
- $ open http://localhost:5000
103
-
104
- # Restore test db to run tests
105
- $ docker exec explainshell_db_1 mongorestore -d explainshell_tests /tmp/dump/explainshell
106
-
107
- $ docker exec explainshell_web_1 make tests
108
- ..............................................................................
109
- ----------------------------------------------------------------------
110
- Ran 79 tests in 3.847s
111
-
112
- OK
113
- ```
81
+ Note that if you've setup using the docker instructions above, echo will already be in the database.
0 commit comments