Skip to content

Commit cb9f62e

Browse files
committed
Updated the help function
1 parent 486aaed commit cb9f62e

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

scripts/color.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def guard(f):
4242
@wraps(f)
4343
def g(*args, **kwargs):
4444
try:
45-
f(*args, **kwargs)
45+
return f(*args, **kwargs)
46+
except BaseException as e:
47+
raise e
4648
finally:
4749
print(END, end = "")
4850
return g
@@ -77,6 +79,36 @@ def bold(*args, **kwargs):
7779
def header(*args, **kwargs):
7880
print(*args, **kwargs)
7981

82+
def _split_without_removing(text, delimeter):
83+
iterator = iter(text.split(delimeter))
84+
try:
85+
l = [next(iterator)]
86+
while True:
87+
i = next(iterator)
88+
l.append(delimeter)
89+
l.append(i)
90+
except StopIteration:
91+
pass
92+
return l
93+
94+
def _split_multiple_without_removing(text, delimeters):
95+
text = [text]
96+
for delimeter in delimeters:
97+
temp = []
98+
for t in text:
99+
temp.extend(_split_without_removing(t, delimeter))
100+
text = temp
101+
return text
102+
103+
@guard
104+
def modify_words(text, words, color = '', style = '', replacement_rule = lambda x: x):
105+
t = ""
106+
for word in _split_multiple_without_removing(text, words):
107+
if word in words:
108+
t += color + style + replacement_rule(word) + END
109+
else:
110+
t += word
111+
return t
112+
80113
if __name__ == "__main__":
81-
with Modify(Colors.CYAN, Styles.ITALIC):
82-
print("asd")
114+
print(modify_words("Merhaba dünya haha", ["dünya"], Colors.RED))

scripts/manage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from os.path import join
33
from functools import wraps
4-
from color import error, warning, success
4+
from color import error, warning, success, Styles, modify_words
55
from difflib import SequenceMatcher
66
import sys
77

@@ -101,9 +101,9 @@ def call(cls, cmd, jobname):
101101
@app.command("release", "dev")
102102
def build(app, job = None):
103103
"""Builds the docs.
104-
* Increases the project version if 'release' argument is given.
105-
* Opens the docs/index.html in browser if 'dev' argument is given.
106-
* Moves them to where they are needed if 'release' or 'dev' argument is given."""
104+
* Increases the project version if [release] argument is given.
105+
* Opens the docs/index.html in browser if [dev] argument is given.
106+
* Moves them to where they are needed if [release] or [dev] argument is given."""
107107

108108
# should we do that at the start so that it affects this release or at the end so that it doesn't run if there is an exception?
109109
if job == "release":
@@ -166,11 +166,11 @@ def version(app, field):
166166
def help(app, method = None):
167167
"Displays a help message for the given argument."
168168
if method is None:
169-
print("Possible arguments for the application:\n")
169+
print("Valid arguments for the application:\n")
170170
for i in app.procedures:
171-
print(f"- {i:<20}" + app.procedures[i][0].__doc__)
171+
print(f"- {i:<20}" + modify_words(app.procedures[i][0].__doc__, words = tuple(map(lambda x: f"[{x}]", app.procedures[i][1])), style = Styles.BOLD, replacement_rule = lambda x: x[1:-1]))
172172
else:
173-
print(f"{method}:", app.procedures[method][0].__doc__)
173+
print(f"{method}:", modify_words(app.procedures[method][0].__doc__, words = tuple(map(lambda x: f"[{x}]", app.procedures[method][1])), style = Styles.BOLD, replacement_rule = lambda x: x[1:-1]))
174174

175175
if __name__ == "__main__":
176176
import sys

0 commit comments

Comments
 (0)