交互模式

除了从命令行运行单个命令外,cliff 还支持交互模式,在这种模式下,用户会看到一个单独的命令 shell。从命令行可用的所有命令插件都会自动配置为 shell 中的命令。

请参阅 cmd2 文档以获取有关 shell 功能的更多详细信息。

示例

如果命令行中未指定命令,则 cliffdemo 应用程序将进入交互模式。

(.venv)$ cliffdemo
(cliffdemo) help

Shell commands (type help <topic>):
===================================
cmdenvironment  edit  hi       l   list  pause  r    save  shell      show
ed              help  history  li  load  py     run  set   shortcuts

Undocumented commands:
======================
EOF  eof  exit  q  quit

Application commands (type help <topic>):
=========================================
files  help  simple  file  error  two part

要获取内置命令或应用程序命令的说明,请使用 help 命令

(cliffdemo) help simple
usage: simple [-h]

A simple command that prints a message.

optional arguments:
  -h, --help  Show help message and exit.

可以运行命令,包括选项和参数,就像在常规命令行中一样

(cliffdemo) simple
sending greeting
hi!
(cliffdemo) files
+----------------------+-------+
|         Name         |  Size |
+----------------------+-------+
| .git                 |   578 |
| .gitignore           |   268 |
| .tox                 |   238 |
| .venv                |   204 |
| announce.rst         |  1015 |
| announce.rst~        |   708 |
| cliff                |   884 |
| cliff.egg-info       |   340 |
| cliffdemo.log        |  2193 |
| cliffdemo.log.1      | 10225 |
| demoapp              |   408 |
| dist                 |   136 |
| distribute_setup.py  | 15285 |
| distribute_setup.pyc | 15196 |
| docs                 |   238 |
| LICENSE              | 11358 |
| Makefile             |   376 |
| Makefile~            |    94 |
| MANIFEST.in          |   186 |
| MANIFEST.in~         |   344 |
| README.rst           |  1063 |
| setup.py             |  5855 |
| setup.py~            |  8128 |
| tests                |   204 |
| tox.ini              |    76 |
| tox.ini~             |   421 |
+----------------------+-------+
(cliffdemo)