Fix printings

This commit is contained in:
Константин Шуткин 2024-02-25 14:55:39 +03:00
parent 0051341d5e
commit cf7af2a2c8
2 changed files with 14 additions and 20 deletions

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python3
import sys, os, subprocess
def print_help():
help_text = f"""
help_text = f"""
Usage: {os.path.basename(__file__)} $1 $2 $3
required:
@ -11,25 +10,23 @@ required:
optional:
$3 - description of service
"""
print(help_text)
"""
number_of_required_arguments = 2
number_of_optional_arguments = 1
if len(sys.argv) == 1:
print_help()
print(help_text)
sys.exit()
elif sys.argv[1] in ["help", "-h"]:
print_help()
print(help_text)
sys.exit()
elif len(sys.argv) - 1 < number_of_required_arguments:
print(f"You provided not enough arguments")
print_help()
print(help_text)
sys.exit(1)
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
print(f"You provided extra arguments")
print_help()
print(help_text)
sys.exit(1)
name_of_service = sys.argv[1]
@ -38,11 +35,11 @@ description = sys.argv[3] if sys.argv[3:4] else "" # empty if no description
if not os.path.isabs(path_to_script):
print("Path to script should be absolute!")
print_help()
print(help_text)
sys.exit(1)
elif not os.path.isfile(path_to_script):
print("Path to script should exist and must be file!")
print_help()
print(help_text)
sys.exit(1)

View File

@ -1,32 +1,29 @@
#!/usr/bin/env python3
import sys, os, subprocess
def print_help():
help_text = f"""
help_text = f"""
Usage: {os.path.basename(__file__)} $1 $2
required:
$1 - name of service
$2 - calendar ()
"""
print(help_text)
"""
number_of_required_arguments = 2
number_of_optional_arguments = 0
if len(sys.argv) == 1:
print_help()
print(help_text)
sys.exit()
elif sys.argv[1] in ["help", "-h"]:
print_help()
sys.exit()
print(help_text)
elif len(sys.argv) - 1 < number_of_required_arguments:
print(f"You provided not enough arguments")
print_help()
print(help_text)
sys.exit(1)
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
print(f"You provided extra arguments")
print_help()
print(help_text)
sys.exit(1)
name_of_service = sys.argv[1]