simple-project-tracker 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. simple_project_tracker-1.0.0.dist-info/METADATA +174 -0
  2. simple_project_tracker-1.0.0.dist-info/RECORD +47 -0
  3. simple_project_tracker-1.0.0.dist-info/WHEEL +5 -0
  4. simple_project_tracker-1.0.0.dist-info/entry_points.txt +3 -0
  5. simple_project_tracker-1.0.0.dist-info/licenses/LICENSE +21 -0
  6. simple_project_tracker-1.0.0.dist-info/top_level.txt +1 -0
  7. tracker/__init__.py +5 -0
  8. tracker/__main__.py +6 -0
  9. tracker/cli/__init__.py +0 -0
  10. tracker/cli/app.py +393 -0
  11. tracker/cli/commands.py +1297 -0
  12. tracker/config/__init__.py +0 -0
  13. tracker/config/defaults.py +180 -0
  14. tracker/config/keys.py +110 -0
  15. tracker/config/metadata.py +81 -0
  16. tracker/config/paths.py +172 -0
  17. tracker/config/settings.py +246 -0
  18. tracker/config/writer.py +113 -0
  19. tracker/core/__init__.py +0 -0
  20. tracker/core/daemon.py +613 -0
  21. tracker/core/discovery.py +212 -0
  22. tracker/core/frecency.py +142 -0
  23. tracker/core/identity.py +121 -0
  24. tracker/core/inspect.py +382 -0
  25. tracker/core/labels.py +109 -0
  26. tracker/core/models.py +152 -0
  27. tracker/core/selection.py +646 -0
  28. tracker/core/storage.py +59 -0
  29. tracker/core/undo.py +63 -0
  30. tracker/core/view.py +48 -0
  31. tracker/py.typed +0 -0
  32. tracker/share/completion.bash +7 -0
  33. tracker/share/completion.fish +12 -0
  34. tracker/share/completion.zsh +13 -0
  35. tracker/share/help.txt +523 -0
  36. tracker/share/settings.toml +245 -0
  37. tracker/ui/__init__.py +0 -0
  38. tracker/ui/ansi.py +128 -0
  39. tracker/ui/ask.py +21 -0
  40. tracker/ui/details.py +172 -0
  41. tracker/ui/help.py +234 -0
  42. tracker/ui/render.py +548 -0
  43. tracker/util/__init__.py +0 -0
  44. tracker/util/compat.py +17 -0
  45. tracker/util/files.py +118 -0
  46. tracker/util/text.py +303 -0
  47. tracker/util/unknown.py +48 -0
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple-project-tracker
3
+ Version: 1.0.0
4
+ Summary: Simple project tracker
5
+ Author-email: MattFor <mattfor@relaxy.xyz>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/MattFor/tracker
8
+ Project-URL: Source, https://github.com/MattFor/tracker
9
+ Project-URL: Mirror, https://codeberg.org/MattFor/tracker
10
+ Project-URL: Issues, https://github.com/MattFor/tracker/issues
11
+ Project-URL: Changelog, https://github.com/MattFor/tracker/blob/master/CHANGELOG.md
12
+ Keywords: cli,projects,git,tracker
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Operating System :: MacOS :: MacOS X
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Topic :: Software Development
26
+ Classifier: Topic :: Utilities
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.11
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Dynamic: license-file
32
+
33
+ # simple-project-tracker
34
+
35
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
36
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
37
+
38
+ A simple, but very customizable tracker to keep track of your projects, their states and
39
+ your notes on them.
40
+
41
+ ```
42
+ TID | ID | NAME | STATUS | LAST TOUCHED | NOTE
43
+ --- | -- | ----------------------------- | ------- | ------------ | ---------------------
44
+ 1 | 8 | tracker | dev | 1m ago | release 1.0.0 today
45
+ 2 | 3 | von-neumann-machine-simulator | dev | 23m ago | review saturday
46
+ 3 | 26 | discord-profile-studio | stable | 1h ago
47
+ ```
48
+
49
+ ## Contents
50
+
51
+ - [Install](#install)
52
+ - [Commands](#commands)
53
+ - [Selecting projects](#selecting-projects)
54
+ - [Configuration](#configuration)
55
+ - [Development](#development)
56
+ - [License](#license)
57
+
58
+ ## Install
59
+
60
+ ```sh
61
+ ./install.sh # ~/.local
62
+ sudo ./install.sh # /usr/local
63
+ ./install.sh --daemon # also install the daemon autostart entry
64
+ ./install.sh --uninstall
65
+ ```
66
+
67
+ Python 3.11+. Then `t init ~/(your project directory)` to fill the database.
68
+
69
+ ## Commands
70
+
71
+ | Command | Aliases | What it does |
72
+ |--------------|-------------------|----------------------------------------------------------------------|
73
+ | `list` | `l`, `ls` | List projects, with search, regex, filters and setting overrides |
74
+ | `check` | `c`, `cc`, `info` | Everything about a project: git state, size, language, version, note |
75
+ | `add` | `a` | Track a project, or scan a directory and track what is inside |
76
+ | `remove` | `rm`, `r`, `del` | Stop tracking projects (files untouched) |
77
+ | `forget` | `ignore` | Stop tracking and keep scans from finding it again |
78
+ | `edit` | `e` | Change a `status` or a `note` |
79
+ | `note` | `n`, `sn` | Set a note without naming the field |
80
+ | `status` | `st`, `ss` | List statuses, set one, or move every project from one to another |
81
+ | `init` | `i`, `scan` | Scan a directory and merge the result into the database |
82
+ | `path` | `p`, `where` | Print a project's path, e.g. `cd "$(t path tracker)"` |
83
+ | `undo` | `u`, `revert` | Take back the last change, undo again to put it back |
84
+ | `stats` | `summary` | Totals, a breakdown by status, most and least recently touched |
85
+ | `settings` | `s`, `config` | Show, edit, get or set the configuration |
86
+ | `completion` | | Print a shell completion script for bash, zsh or fish |
87
+ | `daemon` | `d`, `bg` | `start`, `stop`, `restart`, `status`, `log`, `run` |
88
+
89
+ The project goes before or after the command, whichever reads better, and a command fuses
90
+ with its own action:
91
+
92
+ ```sh
93
+ t 12 es blocked # edit status also: t edit 12 status blocked
94
+ t 12 sn review sunday # set note also: t note 12 review sunday
95
+ t dst # daemon status
96
+ t sset ll 30 # settings set display.list_limit 30
97
+ ```
98
+
99
+ A bare word defaults to a project lookup.
100
+
101
+ ```sh
102
+ t tra # the check view for tracker
103
+ t stable # nothing is called that, so every stable project
104
+ t all # everything, no limit
105
+ ```
106
+
107
+ For more information do: `t help`, `t help <command>` or `t help <topic>`. The full guide
108
+ is within `man tracker`.
109
+
110
+ ## Selecting projects
111
+
112
+ | Selector | Means |
113
+ |-------------|-----------------------------------------------------------|
114
+ | `12` | ID or TID 12 |
115
+ | `i:12` | The permanent ID, `id:` and `#12` too |
116
+ | `t:12` | The temporary ID, `tid:`, `@12` and `:12` too |
117
+ | `3-7`,`5+3` | A range, either direction, or a project and the next few |
118
+ | `s:blocked` | Every project with that status, `st:` and `status:` too |
119
+ | `name` | Exact or partial name, or a path, tab completion included |
120
+ | `all` | Every tracked project |
121
+
122
+ A temporary ID is the index of the latest output.
123
+
124
+ When a partial name matches several projects, it's settled by
125
+ `projects.conflict_resolution_preference`.
126
+
127
+ ## Configuration
128
+
129
+ ```sh
130
+ t settings # everything (default deviations marked)
131
+ t settings edit # open in $EDITOR
132
+ t sset list_limit 30 # rewrites that one line
133
+ t list ll=5 rt=true # override for one command only
134
+ ```
135
+
136
+ A setting can be named in full, by its bare name, by a prefix, by the start of every word
137
+ or by its initials, with the section shortening the same way: `display.list_limit`,
138
+ `list_limit`, `list_lim`, `l_l`, `ll`, `d.ll`. Ambiguities are reported.
139
+
140
+ | Setting | What it does |
141
+ |-------------------------------------|-------------------------------------------------------------|
142
+ | `display.filter` | Filters every listing, e.g. `["-s:archive"]` |
143
+ | `display.columns`, `display.format` | Which columns, or a row layout of your own |
144
+ | `display.relative_times` | `2 days ago` instead of a timestamp |
145
+ | `display.name_max_width` | Shorten long names, `truncate` or `abbreviate` |
146
+ | `sorting.by`, `sorting.direction` | `last_touched`, `last_used`, `name`, `status`, `id`, `path` |
147
+ | `projects.ignore`, `.ignore_files` | Directories and files that never count as your own work |
148
+ | `projects.auto_status` | Status from how long ago a project was touched |
149
+ | `scan.detect_moves` | A moved project keeps its entry instead of looking deleted |
150
+ | `daemon.paths`, `daemon.interval` | What the background scanner watches, and how often |
151
+
152
+ Notes can colour themselves: `t note 12 {red}broken{/} since friday`.
153
+
154
+ ## Development
155
+
156
+ ```sh
157
+ make dev # editable install plus ruff, basedpyright, pytest
158
+ make check # format, lint, types and tests (what CI runs)
159
+ ```
160
+
161
+ ## Disclosure
162
+
163
+ LLMs were used to:
164
+
165
+ - write the help section
166
+ - write the man page
167
+ - check for critical issues and annotation errors
168
+
169
+ HOWEVER, the output was then manually reviewed and issues were fixed by a human.
170
+
171
+ ## License
172
+
173
+ MIT [LICENSE](LICENSE).
174
+ By MattFor.
@@ -0,0 +1,47 @@
1
+ simple_project_tracker-1.0.0.dist-info/licenses/LICENSE,sha256=g3pm9QNICLWqd781GBeloDbp5XMlwRrBCWOn1dlcW4I,1064
2
+ tracker/__init__.py,sha256=eBsP_LY8s8vvzKVwBVhV1pp90hmKGRcTRijyFL72L6k,102
3
+ tracker/__main__.py,sha256=jeGiXw1aaE09qtu4RQW_xa1kzMpGrj2XcRe2LzaV16w,91
4
+ tracker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ tracker/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ tracker/cli/app.py,sha256=qm2DXg5K4xo4GzjYNLxVB6PcCU61lYSb6iJLxdaMMTE,8012
7
+ tracker/cli/commands.py,sha256=IYNaqmR6Luf5eJaB9bBr7aALAndtImxSwSl3b8sB8nY,28338
8
+ tracker/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ tracker/config/defaults.py,sha256=unPiz7O_ex0p1zhgR_HvbvJljKdIEd6fI8-4cLSUywE,3442
10
+ tracker/config/keys.py,sha256=K-2c5w_ep32p4QahAM4BO1DCBGgLjAuCDsGVtw1YM-g,2082
11
+ tracker/config/metadata.py,sha256=wJ9jHqzqTWmT3EO65MNPLeSZGj4L2x8wHchU5ZbkN_k,1786
12
+ tracker/config/paths.py,sha256=vmcLRYToVOJ64eV6K_yILXpXpu_2fpSEK6UYhGXfEz0,3324
13
+ tracker/config/settings.py,sha256=_oS9yOt64Kutk8yzZX6ohcaA_lcgTwKkr78k8j2oyxs,5314
14
+ tracker/config/writer.py,sha256=cJHPnldKOSnl7qOKk97SKcHjN1nv52LWfuc_PK5xXAQ,2478
15
+ tracker/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ tracker/core/daemon.py,sha256=2mGaVd0yNPo4N77nG81_6uFhIecR7UaqP6Kk-nQrWvQ,13743
17
+ tracker/core/discovery.py,sha256=sbKgfyC3HKbNwKHL9D99cH7oqvZpJp-Xzf51lztyOwg,4788
18
+ tracker/core/frecency.py,sha256=zc5n3u-VsYO1H-UAyzvZMPbS_UTfkRstEq5M-Z0D8Wc,2528
19
+ tracker/core/identity.py,sha256=Iyb1FthX9cfKxZp-7SOH5dWh6NLX54hepgHTE9HRd0E,2461
20
+ tracker/core/inspect.py,sha256=zVLD0l-YirUYTipw9Th3Sw5z0sk1rplWRp8S2nwwHeU,7846
21
+ tracker/core/labels.py,sha256=HKejtaEgEcQhx-lOeOskJ7bpE1hgvL9HOhl2feGngrQ,2324
22
+ tracker/core/models.py,sha256=-lp9-mkHEXHzDkV6AlqFN8BlQlCmtUXFtMlDuHSRrjA,3152
23
+ tracker/core/selection.py,sha256=XOyk_Zd5SGkEN_zuD1ZiSjov5g5SHT_S6bOll191um0,15005
24
+ tracker/core/storage.py,sha256=PNdPxDGoQvvT3D5pdcuenFwC7Eit31wYMc7E_re76wk,1322
25
+ tracker/core/undo.py,sha256=ps2daqIzFehcVcWLS3V86ypf7M3fYhWZUgExcBM59t8,1536
26
+ tracker/core/view.py,sha256=54r3PraDOvbvPLj32TI8_Ysrybu-gB2uvLdZMoNtgRg,1125
27
+ tracker/share/completion.bash,sha256=VDQf36XfdnXfFYlhBBYghZhfWBPRSBT2dRT8iznF8so,208
28
+ tracker/share/completion.fish,sha256=0vVvOmX1CtYONmW-FDkoUirZkX4R8A3FIyawTw3ExS0,300
29
+ tracker/share/completion.zsh,sha256=Kwp4N06wp2ZRZ_jiUhXz5r0ZF3xN5f4NzI-s0YRaSls,234
30
+ tracker/share/help.txt,sha256=eiW14kjKYZVObbYM3NudaZVQfkGKQwid1KkX9TekUD4,26030
31
+ tracker/share/settings.toml,sha256=i-2qsdduECyhqy8zTyG0O4tKu4h5CqGmdx6TDLNTu88,6513
32
+ tracker/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
+ tracker/ui/ansi.py,sha256=axUok7BgAFNPLkRrxI6DEOXUtUH3pPro0tmaIcjI9_I,2353
34
+ tracker/ui/ask.py,sha256=OxBM7iDYFpN3GX1ugCdoTqIQeEVPS25z-7u9qrtfUVY,434
35
+ tracker/ui/details.py,sha256=muuG2QuryfH-i8JKYCl6MnMQrGxTRXbo868zDi8yD60,4398
36
+ tracker/ui/help.py,sha256=RUfBYR0wUo73EsF2qJ1dx94qG6eIZpMGzUDVrLfloRA,4652
37
+ tracker/ui/render.py,sha256=RWUAMxV-6si6dP0lFU_DIpApAeQK0iaToZ2rtDSCzjY,12198
38
+ tracker/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ tracker/util/compat.py,sha256=5IO-phVQPQcw6jbFEWVpHNFpxfcRFVeJGotJxz3CaC4,378
40
+ tracker/util/files.py,sha256=opy2CpwzgNy1g4odLthMMvzqCJJSXAqsXDtKU8jHaQU,2110
41
+ tracker/util/text.py,sha256=3pURviQFZ83dpfidVs5kQ60c4dggp7ts8elwl-j4ejA,5606
42
+ tracker/util/unknown.py,sha256=gIDNUrZ0qLgFVy4bO7yvl5j8H6uJPayMUp1DE6c7RJ0,891
43
+ simple_project_tracker-1.0.0.dist-info/METADATA,sha256=QNq2XhAs2YWaoX7uxrYh0xBJF09zS0Jr6qT5112NS_o,7991
44
+ simple_project_tracker-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
45
+ simple_project_tracker-1.0.0.dist-info/entry_points.txt,sha256=tOQFoJ-Ep9Rav8ZdFimrr1mhlCzj9KkK2xmndZ9FuXs,74
46
+ simple_project_tracker-1.0.0.dist-info/top_level.txt,sha256=5d6-AgJ9PHuONh0ZOHelH0Z2fl97aKnDzEaSXzORM4w,8
47
+ simple_project_tracker-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ t = tracker.cli.app:main
3
+ tracker = tracker.cli.app:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MattFor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ tracker
tracker/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from tracker.config.metadata import project
2
+
3
+ __all__ = ["__version__"]
4
+
5
+ __version__ = project.version
tracker/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ import sys
2
+
3
+ from tracker.cli.app import main
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit(main())
File without changes
tracker/cli/app.py ADDED
@@ -0,0 +1,393 @@
1
+ import sys
2
+
3
+ from typing import Any
4
+
5
+ from tracker.ui import ansi
6
+ from tracker.cli import commands
7
+ from tracker.ui.ansi import C
8
+ from tracker.core.storage import load_data
9
+ from tracker.config.settings import Settings
10
+ from tracker.ui.render import print_projects
11
+ from tracker.cli.commands import Context, Handler
12
+
13
+ COMMANDS: dict[str, str] = {
14
+ "version": "version",
15
+ "v": "version",
16
+ "help": "help",
17
+ "h": "help",
18
+ "list": "list",
19
+ "l": "list",
20
+ "ls": "list",
21
+ "add": "add",
22
+ "a": "add",
23
+ "remove": "remove",
24
+ "rm": "remove",
25
+ "r": "remove",
26
+ "delete": "remove",
27
+ "del": "remove",
28
+ "forget": "forget",
29
+ "f": "forget",
30
+ "ignore": "forget",
31
+ "completion": "completion",
32
+ "completions": "completion",
33
+ "check": "check",
34
+ "c": "check",
35
+ "cc": "check",
36
+ "info": "check",
37
+ "edit": "edit",
38
+ "e": "edit",
39
+ "note": "note",
40
+ "n": "note",
41
+ "sn": "note",
42
+ "status": "status",
43
+ "st": "status",
44
+ "ss": "status",
45
+ "init": "init",
46
+ "i": "init",
47
+ "scan": "init",
48
+ "settings": "settings",
49
+ "s": "settings",
50
+ "config": "settings",
51
+ "conf": "settings",
52
+ "daemon": "daemon",
53
+ "d": "daemon",
54
+ "daemonize": "daemon",
55
+ "daemonise": "daemon",
56
+ "background": "daemon",
57
+ "b": "daemon",
58
+ "bg": "daemon",
59
+ "path": "path",
60
+ "p": "path",
61
+ "where": "path",
62
+ "stats": "stats",
63
+ "stat": "stats",
64
+ "summary": "stats",
65
+ "undo": "undo",
66
+ "u": "undo",
67
+ "revert": "undo",
68
+ }
69
+
70
+ HANDLERS: dict[str, Handler] = {
71
+ "version": commands.command_version,
72
+ "help": commands.command_help,
73
+ "list": commands.command_list,
74
+ "add": commands.command_add,
75
+ "remove": commands.command_remove,
76
+ "check": commands.command_check,
77
+ "edit": commands.command_edit,
78
+ "init": commands.command_init,
79
+ "settings": commands.command_settings,
80
+ "daemon": commands.command_daemon,
81
+ "path": commands.command_path,
82
+ "stats": commands.command_stats,
83
+ "undo": commands.command_undo,
84
+ "show": commands.command_show,
85
+ "note": commands.command_note,
86
+ "status": commands.command_status,
87
+ "forget": commands.command_forget,
88
+ "completion": commands.command_completion,
89
+ }
90
+
91
+ GREEDY = frozenset({"add", "completion", "edit", "note", "status"})
92
+
93
+ SUBJECT = frozenset(
94
+ {"check", "edit", "forget", "note", "path", "remove", "show", "status"}
95
+ )
96
+
97
+ ACTIONS: dict[str, frozenset[str]] = {
98
+ "edit": frozenset(commands.FIELD_ALIASES),
99
+ "forget": frozenset({"list", "l", "show", "clear", "c", "reset", "allow"}),
100
+ "settings": frozenset(
101
+ {"edit", "e", "path", "p", "where", "w", "get", "g", "set", "s"}
102
+ ),
103
+ "daemon": frozenset(
104
+ {
105
+ "start",
106
+ "s",
107
+ "stop",
108
+ "kill",
109
+ "k",
110
+ "restart",
111
+ "r",
112
+ "status",
113
+ "st",
114
+ "state",
115
+ "log",
116
+ "logs",
117
+ "l",
118
+ "run",
119
+ "foreground",
120
+ "fg",
121
+ }
122
+ ),
123
+ }
124
+
125
+ # Words a command keeps for itself instead of reading them as another command
126
+ KEYWORDS: dict[str, frozenset[str]] = {"list": commands.LIMIT_KEYWORDS}
127
+
128
+ LITERAL = "--"
129
+
130
+ VERBOSE_FLAGS = frozenset({"verbose", "vv"})
131
+
132
+ YES_FLAGS = frozenset({"yes", "y", "force", "f"})
133
+
134
+ COLOUR_FLAGS = frozenset({"color", "colour"})
135
+ NO_COLOUR_FLAGS = frozenset({"no-color", "no-colour", "nocolor", "nocolour"})
136
+
137
+
138
+ def normalise(token: str) -> str:
139
+ return token.lower().strip("-")
140
+
141
+
142
+ def command_of(token: str) -> str | None:
143
+ return COMMANDS.get(normalise(token))
144
+
145
+
146
+ def greedy(token: str) -> bool:
147
+ name = command_of(token)
148
+
149
+ if name is None:
150
+ pair = fuse(token)
151
+ name = pair[0] if pair else None
152
+
153
+ return name in GREEDY
154
+
155
+
156
+ def fuse(token: str) -> tuple[str, str] | None:
157
+ key = normalise(token)
158
+
159
+ for cut in range(1, len(key)):
160
+ name = COMMANDS.get(key[:cut])
161
+
162
+ if name is None:
163
+ continue
164
+
165
+ action = key[cut:]
166
+
167
+ if action in ACTIONS.get(name, frozenset()):
168
+ return name, action
169
+
170
+ return None
171
+
172
+
173
+ def expand(args: list[str]) -> list[str]:
174
+ expanded: list[str] = []
175
+ literal = False
176
+
177
+ for token in args:
178
+ if literal:
179
+ expanded.append(token)
180
+ continue
181
+
182
+ if token == LITERAL:
183
+ literal = True
184
+ expanded.append(token)
185
+ continue
186
+
187
+ name = command_of(token)
188
+
189
+ if name is not None:
190
+ expanded.append(token)
191
+ literal = name in GREEDY
192
+ continue
193
+
194
+ pair = fuse(token)
195
+
196
+ if pair is None:
197
+ expanded.append(token)
198
+ continue
199
+
200
+ literal = pair[0] in GREEDY
201
+
202
+ expanded.extend(pair)
203
+
204
+ return expanded
205
+
206
+
207
+ def help_request(args: list[str]) -> list[str] | None:
208
+ for index, token in enumerate(args):
209
+ if token == LITERAL:
210
+ return None
211
+
212
+ name = command_of(token)
213
+
214
+ if name == "help":
215
+ if index:
216
+ for previous in reversed(args[:index]):
217
+ owner = command_of(previous)
218
+
219
+ if owner is not None:
220
+ return [owner, *args[index + 1 :]]
221
+
222
+ return args[index + 1 :]
223
+
224
+ if name in GREEDY:
225
+ following = index + 1
226
+
227
+ if following == len(args) - 1 and command_of(args[following]) == "help":
228
+ return [name]
229
+
230
+ return None
231
+
232
+ return None
233
+
234
+
235
+ def split(args: list[str]) -> list[tuple[str, list[str]]]:
236
+ args = expand(args)
237
+
238
+ wanted = help_request(args)
239
+
240
+ if wanted is not None:
241
+ return [("help", wanted)]
242
+
243
+ literal = len(args)
244
+
245
+ if LITERAL in args:
246
+ literal = args.index(LITERAL)
247
+ del args[literal]
248
+
249
+ # noinspection shadowing-names
250
+ def command_at(index: int, owner: str = "") -> str | None:
251
+ if index >= literal:
252
+ return None
253
+
254
+ if normalise(args[index]) in KEYWORDS.get(owner, frozenset()):
255
+ return None
256
+
257
+ return command_of(args[index])
258
+
259
+ segments: list[tuple[str, list[str]]] = []
260
+
261
+ index = 0
262
+
263
+ while index < len(args):
264
+ name = command_at(index)
265
+ subject: list[str] = []
266
+
267
+ if name is None:
268
+ while index < len(args) and command_at(index) is None:
269
+ subject.append(args[index])
270
+ index += 1
271
+
272
+ name = command_at(index) if index < len(args) else None
273
+
274
+ if name is None or name not in SUBJECT:
275
+ segments.append(("show", subject))
276
+ continue
277
+
278
+ index += 1
279
+
280
+ if name in GREEDY:
281
+ segments.append((name, subject + args[index:]))
282
+ break
283
+
284
+ collected = list(subject)
285
+
286
+ if index < literal and normalise(args[index]) in ACTIONS.get(name, frozenset()):
287
+ collected.append(args[index])
288
+ index += 1
289
+
290
+ while index < len(args) and command_at(index, name) is None:
291
+ collected.append(args[index])
292
+ index += 1
293
+
294
+ segments.append((name, collected))
295
+
296
+ return segments
297
+
298
+
299
+ def extract_flags(args: list[str]) -> tuple[list[str], dict[str, Any]]:
300
+ flags: dict[str, Any] = {"verbose": False, "yes": False, "colour": None}
301
+
302
+ remaining: list[str] = []
303
+ greedy_reached = False
304
+ literal = False
305
+
306
+ for token in args:
307
+ if literal:
308
+ remaining.append(token)
309
+ continue
310
+
311
+ if token == LITERAL:
312
+ literal = True
313
+ remaining.append(token)
314
+ continue
315
+
316
+ if greedy_reached and not token.startswith("-"):
317
+ remaining.append(token)
318
+ continue
319
+
320
+ if greedy(token):
321
+ greedy_reached = True
322
+
323
+ key = normalise(token)
324
+
325
+ if key in VERBOSE_FLAGS:
326
+ flags["verbose"] = True
327
+ continue
328
+
329
+ if token.startswith("-") and key in YES_FLAGS:
330
+ flags["yes"] = True
331
+ continue
332
+
333
+ if token.startswith("-") and key in NO_COLOUR_FLAGS:
334
+ flags["colour"] = False
335
+ continue
336
+
337
+ if token.startswith("-") and key in COLOUR_FLAGS:
338
+ flags["colour"] = True
339
+ continue
340
+
341
+ remaining.append(token)
342
+
343
+ return remaining, flags
344
+
345
+
346
+ def main(argv: list[str] | None = None) -> int:
347
+ args = list(sys.argv[1:] if argv is None else argv)
348
+
349
+ args, flags = extract_flags(args)
350
+
351
+ settings = Settings()
352
+
353
+ colour = settings["output"]["colour"] if flags["colour"] is None else flags["colour"]
354
+ ansi.configure(bool(colour))
355
+
356
+ for problem in settings.problems:
357
+ print(f"{C.YELLOW}[WARNING] {problem}{C.RESET}", file=sys.stderr)
358
+
359
+ verbose = bool(flags["verbose"] or settings["logging"]["always_verbose"])
360
+
361
+ context = Context(
362
+ settings=settings,
363
+ data=load_data(settings),
364
+ verbose=verbose,
365
+ assume_yes=bool(flags["yes"]),
366
+ )
367
+
368
+ context.log(f"settings: {settings.path}")
369
+ context.log(f"projects: {len(context.data)}")
370
+
371
+ if not args:
372
+ print_projects(context.data, settings)
373
+ return 0
374
+
375
+ status = 0
376
+
377
+ for name, arguments in split(args):
378
+ handler = HANDLERS.get(name)
379
+
380
+ if handler is None:
381
+ print(f"[ERROR] unknown command '{name}'")
382
+ status = 1
383
+ continue
384
+
385
+ try:
386
+ status = handler(context, arguments) or status
387
+ except KeyboardInterrupt:
388
+ print()
389
+ return 130
390
+ except BrokenPipeError:
391
+ return 0
392
+
393
+ return status