commited all contents created by participants
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#!/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'''
|
||||
# si on a l'option
|
||||
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
|
||||
else:
|
||||
# si pas de fallback
|
||||
if not fallback:
|
||||
return True
|
||||
# sinon on retourne le fallback
|
||||
else:
|
||||
return fallback
|
||||
# si on a l'option mais rien derrière
|
||||
else:
|
||||
# si pas de fallback
|
||||
if not fallback:
|
||||
return True
|
||||
# si fallback
|
||||
else:
|
||||
# on renvoie le fallback
|
||||
return fallback
|
||||
# dans les autres cas on renvoie False ou le fallback si défini
|
||||
return fallback
|
||||
Reference in New Issue
Block a user