Skip to content

Commit 8923a6d

Browse files
authored
Merge pull request #217 from realpython/typer-cli-python
Add Typer CLI App code
2 parents 0690fa4 + 97a9937 commit 8923a6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2696
-0
lines changed

typer-cli-python/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# RP To-Do
2+
3+
**RP To-Do** is a command-line interface application built with [Typer](https://typer.tiangolo.com/) to help you manage your to-do list.
4+
5+
## Installation
6+
7+
To run **RP To-Do**, you need to run the following steps:
8+
9+
1. Download the application's source code to a `rptodo_project/` directory
10+
2. Create a Python virtual environment and activate it
11+
12+
```sh
13+
$ cd rptodo_project/
14+
$ python -m venv ./venv
15+
$ source venv/bin/activate
16+
(venv) $
17+
```
18+
19+
2. Install the dependencies
20+
21+
```sh
22+
(venv) $ python -m pip install -r requirements.txt
23+
```
24+
25+
3. Initialize the application
26+
27+
```sh
28+
(venv) $ python -m rptodo init
29+
```
30+
31+
This command asks you to introduce the file path to store the application's database. You can also accept the default file path by pressing Enter.
32+
33+
## Usage
34+
35+
Once you've download the source code and run the installation steps, you can run the following command to access the application's usage description:
36+
37+
```sh
38+
$ python -m rptodo --help
39+
Usage: rptodo [OPTIONS] COMMAND [ARGS]...
40+
41+
Options:
42+
-v, --version Show the application's version and exit.
43+
--install-completion Install completion for the current shell.
44+
--show-completion Show completion for the current shell, to copy it or
45+
customize the installation.
46+
47+
--help Show this message and exit.
48+
49+
Commands:
50+
add Add a new to-do with a DESCRIPTION.
51+
clear Remove all to-dos.
52+
complete Complete a to-do by setting it as done using its TODO_ID.
53+
init Initialize the to-do database.
54+
list List all to-dos.
55+
remove Remove a to-do using its TODO_ID.
56+
```
57+
58+
You can also access the help message for specific commands by typing the command and then `--help`. For example, to display the help content for the `add` command, you can run the following:
59+
60+
```sh
61+
$ python -m rptodo add --help
62+
Usage: rptodo add [OPTIONS] DESCRIPTION...
63+
64+
Add a new to-do with a DESCRIPTION.
65+
66+
Arguments:
67+
DESCRIPTION... [required]
68+
69+
Options:
70+
-p, --priority INTEGER RANGE [default: 2]
71+
--help Show this message and exit.
72+
```
73+
74+
Calling `--help` on each command provides specific and useful information about how to use the command at hand.
75+
76+
## Features
77+
78+
**RP To-Do** has the following features:
79+
80+
| Command | Description |
81+
| ------------------ | ------------------------------------------------------------ |
82+
| `init` | Initializes the application's to-do database. |
83+
| `add DESCRIPTION` | Adds a new to-do to the database with a `DESCRIPTION`. |
84+
| `list` | Lists all the to-dos in the database. |
85+
| `complete TODO_ID` | Completes a to-do by setting it as done using its `TODO_ID`. |
86+
| `remove TODO_ID` | Removes a to-do from the database using its `TODO_ID`. |
87+
| `clear` | Removes all the to-dos by clearing the database. |
88+
89+
## Release History
90+
91+
- 0.1.0
92+
- A work in progress
93+
94+
## About the Author
95+
96+
Leodanis Pozo Ramos - Email: [email protected]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# RP To-Do
2+
3+
**RP To-Do** is a command-line interface application built with [Typer](https://typer.tiangolo.com/) to help you manage your to-do list.
4+
5+
## Installation
6+
7+
To run **RP To-Do**, you need to run the following steps:
8+
9+
1. Download the application's source code to a `rptodo_project/` directory
10+
2. Create a Python virtual environment and activate it
11+
12+
```sh
13+
$ cd rptodo_project/
14+
$ python -m venv ./venv
15+
$ source venv/bin/activate
16+
(venv) $
17+
```
18+
19+
2. Install the dependencies
20+
21+
```sh
22+
(venv) $ python -m pip install -r requirements.txt
23+
```
24+
25+
3. Initialize the application
26+
27+
```sh
28+
(venv) $ python -m rptodo init
29+
```
30+
31+
This command asks you to introduce the file path to store the application's database. You can also accept the default file path by pressing enter.
32+
33+
## Usage
34+
35+
Once you've download the source code and run the installation steps, you can run the following command to access the application's usage description:
36+
37+
```sh
38+
$ python -m rptodo --help
39+
Usage: rptodo [OPTIONS] COMMAND [ARGS]...
40+
41+
Options:
42+
-v, --version Show the application's version and exit.
43+
--install-completion Install completion for the current shell.
44+
--show-completion Show completion for the current shell, to copy it or
45+
customize the installation.
46+
47+
--help Show this message and exit.
48+
49+
Commands:
50+
add Add a new to-do with a DESCRIPTION.
51+
clear Remove all to-dos.
52+
complete Complete a to-do by setting it as done using its TODO_ID.
53+
init Initialize the to-do database.
54+
list List all to-dos.
55+
remove Remove a to-do using its TODO_ID.
56+
```
57+
58+
You can also access the help message for specific commands by typing the command and then `--help`. For example, to display the help content for the `add` command, you can run the following:
59+
60+
```sh
61+
$ python -m rptodo add --help
62+
Usage: rptodo add [OPTIONS] DESCRIPTION...
63+
64+
Add a new to-do with a DESCRIPTION.
65+
66+
Arguments:
67+
DESCRIPTION... [required]
68+
69+
Options:
70+
-p, --priority INTEGER RANGE [default: 2]
71+
--help Show this message and exit.
72+
```
73+
74+
Calling `--help` on each command provides specific and useful information about how to use the command at hand.
75+
76+
## Features
77+
78+
**RP To-Do** has the following features:
79+
80+
| Command | Description |
81+
| ------------------ | ------------------------------------------------------------ |
82+
| `init` | Initializes the application's to-do database. |
83+
| `add DESCRIPTION` | Adds a new to-do to the database with a `DESCRIPTION`. |
84+
| `list` | Lists all the to-dos in the database. |
85+
| `complete TODO_ID` | Completes a to-do by setting it as done using its `TODO_ID`. |
86+
| `remove TODO_ID` | Removes a to-do from the database using its `TODO_ID`. |
87+
| `clear` | Removes all the to-dos by clearing the database. |
88+
89+
## Release History
90+
91+
- 0.1.0
92+
- A work in progress
93+
94+
## About the Author
95+
96+
Leodanis Pozo Ramos - Email: [email protected]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
typer==0.3.2
2+
colorama==0.4.4
3+
shellingham==1.4.0
4+
pytest==6.2.4
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Top-level package for RP To-Do."""
2+
3+
__app_name__ = "rptodo"
4+
__version__ = "0.1.0"
5+
6+
(
7+
SUCCESS,
8+
DIR_ERROR,
9+
FILE_ERROR,
10+
DB_READ_ERROR,
11+
DB_WRITE_ERROR,
12+
JSON_ERROR,
13+
ID_ERROR,
14+
) = range(7)
15+
16+
ERRORS = {
17+
DIR_ERROR: "config directory error",
18+
FILE_ERROR: "config file error",
19+
DB_READ_ERROR: "database read error",
20+
DB_WRITE_ERROR: "database write error",
21+
ID_ERROR: "to-do id error",
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""RP To-Do entry point script."""
2+
3+
from rptodo import cli, __app_name__
4+
5+
6+
def main():
7+
cli.app(prog_name=__app_name__)
8+
9+
10+
if __name__ == "__main__":
11+
main()

0 commit comments

Comments
 (0)