Fix printings
This commit is contained in:
parent
0051341d5e
commit
cf7af2a2c8
|
@ -1,8 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys, os, subprocess
|
import sys, os, subprocess
|
||||||
|
|
||||||
def print_help():
|
help_text = f"""
|
||||||
help_text = f"""
|
|
||||||
Usage: {os.path.basename(__file__)} $1 $2 $3
|
Usage: {os.path.basename(__file__)} $1 $2 $3
|
||||||
|
|
||||||
required:
|
required:
|
||||||
|
@ -11,25 +10,23 @@ required:
|
||||||
|
|
||||||
optional:
|
optional:
|
||||||
$3 - description of service
|
$3 - description of service
|
||||||
"""
|
"""
|
||||||
print(help_text)
|
|
||||||
|
|
||||||
number_of_required_arguments = 2
|
number_of_required_arguments = 2
|
||||||
number_of_optional_arguments = 1
|
number_of_optional_arguments = 1
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif sys.argv[1] in ["help", "-h"]:
|
elif sys.argv[1] in ["help", "-h"]:
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif len(sys.argv) - 1 < number_of_required_arguments:
|
elif len(sys.argv) - 1 < number_of_required_arguments:
|
||||||
print(f"You provided not enough arguments")
|
print(f"You provided not enough arguments")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
|
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
|
||||||
print(f"You provided extra arguments")
|
print(f"You provided extra arguments")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
name_of_service = sys.argv[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):
|
if not os.path.isabs(path_to_script):
|
||||||
print("Path to script should be absolute!")
|
print("Path to script should be absolute!")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif not os.path.isfile(path_to_script):
|
elif not os.path.isfile(path_to_script):
|
||||||
print("Path to script should exist and must be file!")
|
print("Path to script should exist and must be file!")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,29 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys, os, subprocess
|
import sys, os, subprocess
|
||||||
|
|
||||||
def print_help():
|
help_text = f"""
|
||||||
help_text = f"""
|
|
||||||
Usage: {os.path.basename(__file__)} $1 $2
|
Usage: {os.path.basename(__file__)} $1 $2
|
||||||
|
|
||||||
required:
|
required:
|
||||||
$1 - name of service
|
$1 - name of service
|
||||||
$2 - calendar ()
|
$2 - calendar ()
|
||||||
"""
|
"""
|
||||||
print(help_text)
|
|
||||||
|
|
||||||
number_of_required_arguments = 2
|
number_of_required_arguments = 2
|
||||||
number_of_optional_arguments = 0
|
number_of_optional_arguments = 0
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif sys.argv[1] in ["help", "-h"]:
|
elif sys.argv[1] in ["help", "-h"]:
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit()
|
|
||||||
elif len(sys.argv) - 1 < number_of_required_arguments:
|
elif len(sys.argv) - 1 < number_of_required_arguments:
|
||||||
print(f"You provided not enough arguments")
|
print(f"You provided not enough arguments")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
|
elif len(sys.argv) > number_of_required_arguments + number_of_optional_arguments + 1:
|
||||||
print(f"You provided extra arguments")
|
print(f"You provided extra arguments")
|
||||||
print_help()
|
print(help_text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
name_of_service = sys.argv[1]
|
name_of_service = sys.argv[1]
|
||||||
|
|
Loading…
Reference in New Issue