Skip to content

Commit 05b1ea0

Browse files
committed
Add the "seleniumbase print" command with syntax-highlighting
1 parent bbfc354 commit 05b1ea0

File tree

2 files changed

+379
-0
lines changed

2 files changed

+379
-0
lines changed

seleniumbase/console_scripts/run.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sbase install chromedriver
1010
sbase mkdir browser_tests
1111
sbase convert my_old_webdriver_unittest.py
12+
sbase print my_first_test.py -n
1213
sbase translate my_first_test.py --zh -p
1314
sbase extract-objects my_first_test.py
1415
sbase inject-objects my_first_test.py
@@ -67,6 +68,7 @@ def show_basic_usage():
6768
sc += (" install [DRIVER_NAME] [OPTIONS]\n")
6869
sc += (" mkdir [NEW_TEST_DIRECTORY_NAME]\n")
6970
sc += (" convert [PYTHON_WEBDRIVER_UNITTEST_FILE]\n")
71+
sc += (" print [FILE] [OPTIONS]\n")
7072
sc += (" translate [SB_PYTHON_FILE] [LANGUAGE] [ACTION]\n")
7173
sc += (" extract-objects [SB_PYTHON_FILE]\n")
7274
sc += (" inject-objects [SB_PYTHON_FILE] [OPTIONS]\n")
@@ -149,6 +151,20 @@ def show_convert_usage():
149151
print("")
150152

151153

154+
def show_print_usage():
155+
print(" ** print **")
156+
print(" Usage:")
157+
print(" seleniumbase print [FILE] [OPTIONS]")
158+
print(" OR: sbase print [FILE] [OPTIONS]")
159+
print(" Options:")
160+
print(" -n (Add line Numbers to the rows)")
161+
print(" -w (Use word-Wrap for long lines)")
162+
print(" Output:")
163+
print(" Prints the code/text of any file")
164+
print(" with syntax-highlighting.")
165+
print("")
166+
167+
152168
def show_translate_usage():
153169
print(" ** translate **")
154170
print(" Usage:")
@@ -342,6 +358,7 @@ def show_detailed_help():
342358
show_install_usage()
343359
show_mkdir_usage()
344360
show_convert_usage()
361+
show_print_usage()
345362
show_translate_usage()
346363
show_extract_objects_usage()
347364
show_inject_objects_usage()
@@ -390,6 +407,22 @@ def main():
390407
else:
391408
show_basic_usage()
392409
show_convert_usage()
410+
elif command == "print":
411+
if len(command_args) >= 1:
412+
if sys.version_info[0] == 2:
413+
colorama.init(autoreset=True)
414+
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
415+
cr = colorama.Style.RESET_ALL
416+
msg = '"sbase print" does NOT support Python 2! '
417+
msg += 'Try using the Unix "cat" command instead!'
418+
message = "\n" + c5 + msg + cr + "\n"
419+
print("")
420+
raise Exception(message)
421+
from seleniumbase.console_scripts import sb_print
422+
sb_print.main()
423+
else:
424+
show_basic_usage()
425+
show_print_usage()
393426
elif command == "translate":
394427
if len(command_args) >= 1:
395428
if sys.version_info[0] == 2:
@@ -478,6 +511,10 @@ def main():
478511
print("")
479512
show_convert_usage()
480513
return
514+
elif command_args[0] == "print":
515+
print("")
516+
show_print_usage()
517+
return
481518
elif command_args[0] == "translate":
482519
print("")
483520
show_translate_usage()

0 commit comments

Comments
 (0)