Debian Codegraph @

docs/overview/alternatives.md

raw symbols SCIP
1 # Alternatives
2
3 For programs that do not interact with the user in a continuous loop - programs that simply accept a
4 set of arguments from the command line, return results, and do not keep the user within the
5 program's environment - all you need are [sys](https://docs.python.org/3/library/sys.html).argv (the
6 command-line arguments) and [argparse](https://docs.python.org/3/library/argparse.html) (for parsing
7 UNIX-style options and flags). Though some people may prefer
8 [docopt](https://pypi.org/project/docopt) or [click](https://click.palletsprojects.com) to
9 [argparse](https://docs.python.org/3/library/argparse.html).
10
11 The [textual](https://textual.textualize.io/) module is capable of building sophisticated
12 full-screen terminal user interfaces (TUIs) that are not limited to simple text input and output;
13 they can paint the screen with options that are selected from using the cursor keys and even mouse
14 clicks. However, programming a `textual` application is not as straightforward as using `cmd2`.
15
16 Several Python packages exist for building interactive command-line applications approximately
17 similar in concept to [cmd](https://docs.python.org/3/library/cmd.html) applications. None of them
18 share `cmd2`'s close ties to [cmd](https://docs.python.org/3/library/cmd.html), but they may be
19 worth investigating nonetheless.
20
21 [Click](https://click.palletsprojects.com) is a Python package for creating beautiful command line
22 interfaces in a composable way with as little code as necessary. It is more geared towards command
23 line utilities instead of command line interpreters, but it can be used for either.
24
25 Getting a working command-interpreter application based on
26 [Click](https://click.palletsprojects.com) requires a good deal more effort and boilerplate code
27 than `cmd2`. `cmd2` focuses on providing an excellent out-of-the-box experience with as many useful
28 features as possible built in for free with as little work required on the developer's part as
29 possible. We believe that `cmd2` provides developers the easiest way to write a command-line
30 interpreter, while allowing a good experience for end users.
31
32 Historically, [Python Prompt Toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) was
33 considered a powerful but more complex alternative to `cmd2`. However, as of version 4.0.0, `cmd2`
34 utilizes `prompt-toolkit` internally as its REPL engine. This means you get the power and
35 cross-platform compatibility of `prompt-toolkit` with the easy-to-use API of `cmd2`.
36
37 If you are seeking a visually richer end-user experience and don't mind investing more development
38 time, we would recommend checking out [Textual](https://github.com/Textualize/textual) as this can
39 be used to build very sophisticated user interfaces in a terminal that are more akin to feature-rich
40 web GUIs.