%prog [<name>=[value]]

	To show all environment variables, call with no parameters:
		%prog
	To Add/Modify/Delete environment variable:
		%prog <name>=[value]

	If <name> is PATH or PATHEXT, %prog will by default append the value using
	a semicolon as a separator. Use -r to disable this behavior or -a to force
	it for variables other than PATH and PATHEXT.

	If append is prescribed, but the value doesn't exist, the value will be
	created.

	If there is no value, %prog will delete the <name> environment variable.
	i.e. "PATH="

	To remove a specific value or values from a semicolon-separated
	multi-value variable (such as PATH), use --remove-value.

	e.g. enver --remove-value PATH=C:\\Unwanted\\Dir\\In\\Path

	Remove-value matches case-insensitive and also matches any substring
	so the following would also be sufficient to remove the aforementioned
	undesirable dir.

	enver --remove-value PATH=UNWANTED

	Note that %prog does not affect the current running environment, and can
	only affect subsequently spawned applications.

def enver(*args):
	"""
	%prog [<name>=[value]]

	To show all environment variables, call with no parameters:
		%prog
	To Add/Modify/Delete environment variable:
		%prog <name>=[value]

	If <name> is PATH or PATHEXT, %prog will by default append the value using
	a semicolon as a separator. Use -r to disable this behavior or -a to force
	it for variables other than PATH and PATHEXT.

	If append is prescribed, but the value doesn't exist, the value will be
	created.

	If there is no value, %prog will delete the <name> environment variable.
	i.e. "PATH="

	To remove a specific value or values from a semicolon-separated
	multi-value variable (such as PATH), use --remove-value.

	e.g. enver --remove-value PATH=C:\\Unwanted\\Dir\\In\\Path

	Remove-value matches case-insensitive and also matches any substring
	so the following would also be sufficient to remove the aforementioned
	undesirable dir.

	enver --remove-value PATH=UNWANTED

	Note that %prog does not affect the current running environment, and can
	only affect subsequently spawned applications.
	"""
	from optparse import OptionParser
	parser = OptionParser(usage=trim(enver.__doc__))
	parser.add_option(
		'-U', '--user-environment',
		action='store_const', const=UserRegisteredEnvironment,
		default=MachineRegisteredEnvironment,
		dest='class_',
		help="Use the current user's environment",
	)
	parser.add_option(
		'-a', '--append',
		action='store_true', default=False,
		help="Append the value to any existing value (default for PATH and PATHEXT)",
	)
	parser.add_option(
		'-r', '--replace',
		action='store_true', default=False,
		help="Replace any existing value (used to override default append "
		"for PATH and PATHEXT)",
	)
	parser.add_option(
		'--remove-value', action='store_true', default=False,
		help="Remove any matching values from a semicolon-separated "
		"multi-value variable",
	)
	parser.add_option(
		'-e', '--edit', action='store_true', default=False,
		help="Edit the value in a local editor",
	)
	options, args = parser.parse_args(*args)

	try:
		param = args.pop()
		if args:
			parser.error("Too many parameters specified")
			raise SystemExit(1)
		if '=' not in param and not options.edit:
			parser.error("Expected <name>= or <name>=<value>")
			raise SystemExit(2)
		name, sep, value = param.partition('=')
		method_name = 'set'
		if options.remove_value:
			method_name = 'remove_values'
		if options.edit:
			method_name = 'edit'
		method = getattr(options.class_, method_name)
		method(name, value, options)
	except IndexError:
		options.class_.show()