From c968a0cee7ae6980fe4e15757b3eae10f4369a2f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 11 Oct 2013 10:04:46 +0200 Subject: parse command line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gpp.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/gpp.py b/src/gpp.py index 5828a7b..827720a 100644 --- a/src/gpp.py +++ b/src/gpp.py @@ -8,6 +8,23 @@ encoding = 'utf-8' input_file = '/dev/stdin' output_file = '/dev/stdout' +for i in range(1, len(sys.argv)): + arg = sys.argv[i] + i += 1 + if arg in ('-s', '--symbol'): symbol = sys.argv[i] + elif arg in ('-e', '--encoding'): encoding = sys.argv[i] + elif arg in ('-i', '--input'): input_file = sys.argv[i] + elif arg in ('-o', '--output'): output_file = sys.argv[i] + elif arg in ('-f', '--file'): + input_file = sys.argv[i] + output_file = sys.argv[i] + else: + continue + i += 1 + +if input_file == '-': input_file = '/dev/stdin' +if output_file == '-': output_file = '/dev/stdout' + data = None with open(input_file, 'rb') as file: data = file.read().decode(encoding, 'error').split('\n') -- cgit v1.2.3-70-g09d2