-
Notifications
You must be signed in to change notification settings - Fork 4
/
util_argparse.py
41 lines (29 loc) · 1.09 KB
/
util_argparse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import argparse as ap
import sys
class util_argparse:
def __init__( self, script_name = None ):
self.script_name = script_name
self.parser = ap.ArgumentParser()
self.arg = self.parser.add_argument
self.args = {}
def inp_0( self ):
self.arg( 'inp', metavar='INPUT_FILE', type=str, nargs='?', default=None )
def out_0( self ):
self.arg( 'out', metavar='OUTPUT_FILE', type=str, nargs='?', default=None )
def version( self ):
arg( '-v','--version', action='store_true',
help="Prints the current "+self.script_name+" version and exit\n" if self.script_name else "" )
def get_inp_0( self ):
if not 'inp' in self.args:
return None
if self.args['inp'] is None:
return sys.stdin
return self.args['inp']
def get_out_0( self ):
if not 'out' in self.args:
return None
if self.args['out'] is None:
return sys.stdout
return self.args['out']
def parse( self ):
self.args = vars(self.parser.parse_args())