Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
/ python-arg Public archive

[Feature complete] A simple argument parser for Python

License

Notifications You must be signed in to change notification settings

maandree/python-arg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple argument parser for Python

Example usage:
	import sys
	import arg

	def usage():
		print('usage: %s [-v value] [-xy]' % sys.argv[0], file = sys.stderr)
		sys.exit(1)

	xflag = False
	yflag = False
	vflag = None

	parser = arg.Parser(usage = usage)
	for c in parser.flags:
		if c == 'x':
			xflag = True
		elif c == 'y':
			yflag = True
		elif c == 'v':
			vflag = parser.arg
		else:
			usage()

Supports:
	Short flags without arguments
	Short flags with optionally attached arguments
	Joined short flags
	Long flags with optional arguments
	Long flags with mandatory arguments
	Long flags with mandatory attached arguments
	Long flags with mandatory detached arguments
	Long flags with without arguments
	Long flags with only one dash
	Flags not starting with a dash
	Numeral flags
	Stop parsing flags at --
	Mixing flags and arguments
	Stop parsing flags at first argument
	Returning -- as an argument
	Not returning -- as an argument