25 lines
767 B
Python
25 lines
767 B
Python
import argparse
|
|
import time
|
|
|
|
def timer_command(fonction):
|
|
def internal_wrapper(args):
|
|
if args.verbose:
|
|
print("[DEBUG] Lancement de la commande...")
|
|
start_time = time.perf_counter()
|
|
result = fonction(args)
|
|
print(f"[DEBUG] Terminé en {time.perf_counter() - start_time}")
|
|
return result
|
|
return fonction(args)
|
|
return internal_wrapper
|
|
|
|
parser = argparse.ArgumentParser(description="Un scanneur")
|
|
parser.add_argument("-n", "--numbers", nargs= "+", type= int, help="Nombres à additioner")
|
|
parser.add_argument("-v", "--verbose", action="store_true", help="Mode verbeux")
|
|
|
|
@timer_command
|
|
def addition(args):
|
|
return sum(args.numbers)
|
|
|
|
args = parser.parse_args()
|
|
|
|
print(addition(args)) |