Skip to content

Commit cf4abcf

Browse files
committed
adjust docstrings and CHANGELOG
1 parent 5dee53f commit cf4abcf

3 files changed

Lines changed: 31 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
* Renamed the internal class method `FormatCodes.__config_console()` to `FormatCodes._config_console()` to make it callable, but still indicate that it's internal.
2525

2626
**BREAKING CHANGES:**
27+
* The arguments when calling `Console.get_args()` are no longer specified in a single dictionary, but now each argument is passed as a separate keyword argument.
2728
* Replaced the internal `_COMPILED` regex pattern dictionaries with `LazyRegex` objects so it won't compile all regex patterns on library import, but only when they are used for the first time, which improves the library's import time.
2829
* Renamed the internal `_COMPILED` regex pattern dictionaries to `_PATTERNS` for better clarity.
29-
* Removed the import of the `ProgressBar` class from the `__init__.py` file, since it's not a standard class that should be imported directly.
30+
* Removed the import of the `ProgressBar` class from the `__init__.py` file, since it's not an important main class that should be imported directly.
3031
* Renamed the constant `CLR` to `CLI_COLORS` and the constant `HELP` to `CLI_HELP` in the `cli.help` module.
3132
* Changed the default value of the `strip_spaces` param in `Regex.brackets()` from `True` to `False`, since this is more intuitive behavior.
3233

src/xulbux/console.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,28 +209,37 @@ def get_args(
209209
```
210210
3. Positional argument collection using the literals `"before"` or `"after"`:
211211
```python
212-
alias_name="before" # Collects non-flagged args before first flag
213-
alias_name="after" # Collects non-flagged args after last flag
212+
alias_name="before" # COLLECTS NON-FLAGGED ARGS BEFORE FIRST FLAG
213+
alias_name="after" # COLLECTS NON-FLAGGED ARGS AFTER LAST FLAG
214214
```
215215
#### Example usage:
216216
```python
217-
ARGS = Console.get_args(
218-
text="before", # Positional args before flagged args
219-
arg1={"-a1", "--arg1"}, # Just flags
220-
arg2={"-a2", "--arg2"}, # Just flags
221-
arg3={ # With default value
222-
"flags": {"-a3", "--arg3"},
223-
"default": "default_val",
224-
},
217+
Args(
218+
# FOUND TWO POSITIONAL ARGUMENTS BEFORE THE FIRST FLAG
219+
text = ArgResult(exists=True, values=["Hello", "World"]),
220+
# FOUND ONE OF THE SPECIFIED FLAGS WITH A VALUE
221+
arg1 = ArgResult(exists=True, value="value1"),
222+
# FOUND ONE OF THE SPECIFIED FLAGS WITHOUT A VALUE
223+
arg2 = ArgResult(exists=True, value=None),
224+
# DIDN'T FIND ANY OF THE SPECIFIED FLAGS BUT HAS A DEFAULT VALUE
225+
arg3 = ArgResult(exists=False, value="default_val"),
225226
)
226227
```
227228
If the script is called via the command line:\n
228229
`python script.py Hello World -a1 "value1" --arg2`\n
229-
... it would return an `Args` object where:
230-
- `ARGS.text.exists` is `True`, `ARGS.text.values` is `["Hello", "World"]`
231-
- `ARGS.arg1.exists` is `True`, `ARGS.arg1.value` is `"value1"` (flag present with value)
232-
- `ARGS.arg2.exists` is `True`, `ARGS.arg2.value` is `None` (flag present without value)
233-
- `ARGS.arg3.exists` is `False`, `ARGS.arg3.value` is `"default_val"` (not present, has default value)\n
230+
... it would return an `Args` object:
231+
```python
232+
Args(
233+
# FOUND TWO ARGUMENTS BEFORE THE FIRST FLAG
234+
text = ArgResult(exists=True, values=["Hello", "World"]),
235+
# FOUND ONE OF THE SPECIFIED FLAGS WITH A FOLLOWING VALUE
236+
arg1 = ArgResult(exists=True, value="value1"),
237+
# FOUND ONE OF THE SPECIFIED FLAGS BUT NO FOLLOWING VALUE
238+
arg2 = ArgResult(exists=True, value=None),
239+
# DIDN'T FIND ANY OF THE SPECIFIED FLAGS AND HAS NO DEFAULT VALUE
240+
arg3 = ArgResult(exists=False, value="default_val"),
241+
)
242+
```
234243
---------------------------------------------------------------------------------------------------------
235244
If an arg, defined with flags in `find_args`, is NOT present in the command line:
236245
* `exists` will be `False`
@@ -1128,13 +1137,14 @@ class ProgressBar:
11281137
-------------------------------------------------------------------------------------------------
11291138
- `min_width` -⠀the min width of the progress bar in chars
11301139
- `max_width` -⠀the max width of the progress bar in chars
1131-
- `bar_format` -⠀the format string used to render the progress bar, containing placeholders:
1140+
- `bar_format` -⠀the format strings used to render the progress bar, containing placeholders:
11321141
* `{label}` `{l}`
11331142
* `{bar}` `{b}`
11341143
* `{current}` `{c}`
11351144
* `{total}` `{t}`
11361145
* `{percentage}` `{percent}` `{p}`
11371146
- `limited_bar_format` -⠀a simplified format string used when the console width is too small
1147+
for the normal `bar_format`
11381148
- `chars` -⠀a tuple of characters ordered from full to empty progress<br>
11391149
The first character represents completely filled sections, intermediate
11401150
characters create smooth transitions, and the last character represents
@@ -1203,13 +1213,13 @@ def set_bar_format(
12031213
) -> None:
12041214
"""Set the format string used to render the progress bar.\n
12051215
--------------------------------------------------------------------------------------------------
1206-
- `bar_format` -⠀the format string used to render the progress bar, containing placeholders:
1216+
- `bar_format` -⠀the format strings used to render the progress bar, containing placeholders:
12071217
* `{label}` `{l}`
12081218
* `{bar}` `{b}`
12091219
* `{current}` `{c}`
12101220
* `{total}` `{t}`
12111221
* `{percentage}` `{percent}` `{p}`
1212-
- `limited_bar_format` -⠀a simplified format string used when the console width is too small
1222+
- `limited_bar_format` -⠀a simplified format strings used when the console width is too small
12131223
- `sep` -⠀the separator string used to join multiple format strings
12141224
--------------------------------------------------------------------------------------------------
12151225
The bar format (also limited) can additionally be formatted with special formatting codes. For

src/xulbux/regex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def brackets(
3535
- `bracket1` -⠀the opening bracket (e.g. `(`, `{`, `[` ...)
3636
- `bracket2` -⠀the closing bracket (e.g. `)`, `}`, `]` ...)
3737
- `is_group` -⠀whether to create a capturing group for the content inside the brackets
38-
- `strip_spaces` -⠀whether to ignore spaces around the content inside the brackets
38+
- `strip_spaces` -⠀whether to strip spaces from the bracket content or not
3939
- `ignore_in_strings` -⠀whether to ignore closing brackets that are inside
4040
strings/quotes (e.g. `'…)…'` or `"…)…"`)\n
4141
---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)