Skip to content

Commit a9eceb8

Browse files
committed
Fix release date & restructure CLI commands
1 parent abce5ca commit a9eceb8

6 files changed

Lines changed: 44 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
<span id="v1-9-7" />
1919

20-
## ... `v1.9.7`
20+
## 26.04.2026 `v1.9.7`
2121

22-
* Created a new CLI command `xulbux-fc`, which allows you to parse and render a given string's format codes as ANSI console output.
22+
* Restructured CLI commands under a single `xulbux-lib` entry point:
23+
- `xulbux-lib` shows library info.
24+
- `xulbux-lib fc` (*new*) parses and renders a string's format codes as ANSI console output.
2325
* Added `.get()` method to `ParsedArgData` for safe index access on parsed argument values.
2426
* Added missing `__init__.py` files to the `base` and `cli` subpackages.
2527
* Fixed `ModuleNotFoundError` caused by `mypyc` compiling `__init__.py` files, which broke subpackage imports.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ pip install --upgrade xulbux
3535

3636
When the library is installed, the following commands are available in the console:
3737

38-
| Command | Description |
39-
| :------------ | :--------------------------------------------------------------- |
40-
| `xulbux-help` | Show some information about the library. |
41-
| `xulbux-fc` | Parse and render a string's format codes as ANSI console output. |
38+
| Command | Description |
39+
| :---------------- | :--------------------------------------------------------------- |
40+
| `xulbux-lib` | Show some information about the library. |
41+
| `xulbux-lib fc` | Parse and render a string's format codes as ANSI console output. |
4242

4343
<br>
4444

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ keywords = [
110110
"License" = "https://github.com/xulbux/python-lib-xulbux/blob/main/LICENSE"
111111

112112
[project.scripts]
113-
xulbux-help = "xulbux.cli.help:show_help"
114-
xulbux-fc = "xulbux.cli.tools:render_format_codes"
113+
xulbux-lib = "xulbux.cli:main"
115114

116115
[tool.flake8]
117116
max-complexity = 12

src/xulbux/cli/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
3+
4+
def main() -> None:
5+
"""Main entry point for the `xulbux-lib` CLI command."""
6+
match sys.argv[1] if len(sys.argv) > 1 else "":
7+
case "fc":
8+
from .tools import render_format_codes
9+
render_format_codes()
10+
case _:
11+
from .help import show_help
12+
show_help()

src/xulbux/cli/help.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
def get_latest_version() -> Optional[str]:
12+
"""Fetches the latest version of the library from PyPI."""
1213
with _request.urlopen(URL) as response:
1314
if response.status == 200:
1415
data = _json.load(response)
@@ -18,6 +19,8 @@ def get_latest_version() -> Optional[str]:
1819

1920

2021
def is_latest_version() -> Optional[bool]:
22+
"""Checks if the currently installed version of the
23+
library is the latest one available on PyPI."""
2124
try:
2225
if (latest := get_latest_version()) in {"", None}:
2326
return None
@@ -34,44 +37,52 @@ def is_latest_version() -> Optional[bool]:
3437
CLI_COLORS = {
3538
"border": "dim|br:black",
3639
"class": "br:cyan",
40+
"cmd": "green",
3741
"const": "br:blue",
38-
"func": "br:green",
42+
"fn": "br:green",
3943
"heading": "br:white",
4044
"import": "magenta",
4145
"lib": "br:magenta",
42-
"link": "u|br:blue",
46+
"link": "br:blue",
4347
"notice": "br:yellow",
4448
"punctuator": "br:black",
4549
"text": "white",
4650
}
4751
CLI_HELP = FormatCodes.to_ansi(
48-
rf""" [_|b|#7075FF] __ __
52+
rf"""[_]
53+
[b|#7075FF] __ __
4954
[b|#7075FF] _ __ __ __/ / / /_ __ ___ __
5055
[b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
5156
[b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
5257
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|#000|BG:#8085FF] v[b]{__version__} [*|dim|{CLI_COLORS["notice"]}]({"" if IS_LATEST_VERSION else " (newer available)"})[*]
5358
54-
[i|#9095FF]A TON OF COOL FUNCTIONS, YOU NEED![*]
59+
[i|#9095FF]Simplify common programming tasks![*]
5560
61+
[b|{CLI_COLORS["heading"]}](Commands:)[*]
62+
[{CLI_COLORS["border"]}](╭───────────────────────────────────────────────────╮)[*]
63+
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["cmd"]}]xulbux-lib[*] [{CLI_COLORS["text"]}]Show library info and usage[*] [{CLI_COLORS["border"]}](│)[*]
64+
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["cmd"]}]xulbux-lib [b|{CLI_COLORS["fn"]}](fc) [{CLI_COLORS["text"]}]Render a string's format codes[*] [{CLI_COLORS["border"]}](│)[*]
65+
[{CLI_COLORS["border"]}](╰───────────────────────────────────────────────────╯)[*]
5666
[b|{CLI_COLORS["heading"]}](Usage:)[*]
5767
[{CLI_COLORS["border"]}](╭───────────────────────────────────────────────────╮)[*]
5868
[{CLI_COLORS["border"]}](│) [i|{CLI_COLORS["punctuator"]}](# LIBRARY CONSTANTS)[*] [{CLI_COLORS["border"]}](│)[*]
5969
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["import"]}]from [{CLI_COLORS["lib"]}]xulbux[{CLI_COLORS["punctuator"]}].[{CLI_COLORS["lib"]}]base[{CLI_COLORS["punctuator"]}].[{CLI_COLORS["lib"]}]consts [{CLI_COLORS["import"]}]import [{CLI_COLORS["const"]}]COLOR[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["const"]}]CHARS[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["const"]}]ANSI[*] [{CLI_COLORS["border"]}](│)[*]
6070
[{CLI_COLORS["border"]}](│) [i|{CLI_COLORS["punctuator"]}](# Main Classes)[*] [{CLI_COLORS["border"]}](│)[*]
6171
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["import"]}]from [{CLI_COLORS["lib"]}]xulbux [{CLI_COLORS["import"]}]import [{CLI_COLORS["class"]}]Code[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["class"]}]Color[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["class"]}]Console[{CLI_COLORS["punctuator"]}], ...[*] [{CLI_COLORS["border"]}](│)[*]
6272
[{CLI_COLORS["border"]}](│) [i|{CLI_COLORS["punctuator"]}](# module specific imports)[*] [{CLI_COLORS["border"]}](│)[*]
63-
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["import"]}]from [{CLI_COLORS["lib"]}]xulbux[{CLI_COLORS["punctuator"]}].[{CLI_COLORS["lib"]}]color [{CLI_COLORS["import"]}]import [{CLI_COLORS["func"]}]rgba[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["func"]}]hsla[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["func"]}]hexa[*] [{CLI_COLORS["border"]}](│)
73+
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["import"]}]from [{CLI_COLORS["lib"]}]xulbux[{CLI_COLORS["punctuator"]}].[{CLI_COLORS["lib"]}]color [{CLI_COLORS["import"]}]import [{CLI_COLORS["fn"]}]rgba[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["fn"]}]hsla[{CLI_COLORS["punctuator"]}], [{CLI_COLORS["fn"]}]hexa[*] [{CLI_COLORS["border"]}](│)
6474
[{CLI_COLORS["border"]}](╰───────────────────────────────────────────────────╯)[*]
6575
[b|{CLI_COLORS["heading"]}](Documentation:)[*]
6676
[{CLI_COLORS["border"]}](╭───────────────────────────────────────────────────╮)[*]
67-
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["text"]}]For more information see the GitHub page. [{CLI_COLORS["border"]}](│)[*]
68-
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["link"]}](https://github.com/xulbux/python-lib-xulbux/wiki) [{CLI_COLORS["border"]}](│)[*]
77+
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["text"]}]For more information see the GitHub wiki page: [{CLI_COLORS["border"]}](│)[*]
78+
[{CLI_COLORS["border"]}](│) [{CLI_COLORS["link"]}|link:https://github.com/xulbux/python-lib-xulbux/wiki](github.com/xulbux/python-lib-xulbux/wiki) [{CLI_COLORS["border"]}](│)[*]
6979
[{CLI_COLORS["border"]}](╰───────────────────────────────────────────────────╯)[*]
7080
[_]"""
7181
)
7282

7383

7484
def show_help() -> None:
85+
"""CLI command function for `xulbux-lib` command, which shows some information about the library."""
7586
FormatCodes._config_console()
7687
print(CLI_HELP)
7788
Console.pause_exit(" [dim](Press any key to exit...)\n\n", pause=True)

src/xulbux/cli/tools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44

55
def render_format_codes():
6+
"""CLI command function for `xulbux-lib fc` command, which allows you to parse
7+
and render a given string's format codes as ANSI console output."""
68
args = Console.get_args({"input": "before"})
9+
vals = args.input.values[1:] # EXCLUDE THE COMMAND ITSELF
710

8-
if not args.input.values:
11+
if not vals:
912
FormatCodes.print("\n[_|i|dim]Provide a string to parse and render\n"
1013
"its format codes as ANSI console output.[_]\n")
1114

1215
else:
13-
ansi = FormatCodes.to_ansi("".join(args.input.values))
16+
ansi = FormatCodes.to_ansi("".join(vals))
1417
ansi_escaped = FormatCodes.escape_ansi(ansi)
1518
ansi_stripped = FormatCodes.remove_ansi(ansi)
1619

0 commit comments

Comments
 (0)