22 lines
744 B
Python
22 lines
744 B
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
|
|
def obtenir ( option, fallback=False ) :
|
|
'''String -> String/Boolean
|
|
Si l'option demandée n'existe pas, renvoie False.
|
|
Si l'option demandée existe'''
|
|
if option in sys.argv:
|
|
index = sys.argv.index( option ) + 1
|
|
# si on a quelque chose après notre option
|
|
if len( sys.argv ) > index :
|
|
# si ce quelque chose ne commence pas par -
|
|
if sys.argv[ index ][0] != '-':
|
|
return sys.argv[ index ]
|
|
# si c'est le cas on a à priori une option booléenne, on renvoie true
|
|
else:
|
|
return True
|
|
# dans les autres cas on renvoie False ou le fallback si défini
|
|
return fallback
|