#!/usr/bin/python2.7
# Copyright (C) 2010, Thomas Leonard
# See the README file for details, or visit http://0install.net.

from __future__ import print_function

import locale
import logging
from logging import warn
try:
	locale.setlocale(locale.LC_ALL, '')
except locale.Error:
	warn('Error setting locale (eg. Invalid locale)')

import sys

## PATH ##

from optparse import OptionParser

from zeroinstall import _

parser = OptionParser(usage="usage: %prog [options] alias [interface [main]]")
parser.add_option("-c", "--command", help="the command the alias will run (default 'run')", metavar='COMMNAD')
parser.add_option("-m", "--manpage", help="show the manual page for an existing alias", action='store_true')
parser.add_option("-r", "--resolve", help="show the URI for an alias", action='store_true')
parser.add_option("-v", "--verbose", help="more verbose output", action='count')
parser.add_option("-V", "--version", help="display version information", action='store_true')
#parser.add_option("-d", "--dir", help="install in DIR", dest="user_path", metavar="DIR")

(options, args) = parser.parse_args()

if options.verbose:
	logger = logging.getLogger()
	if options.verbose == 1:
		logger.setLevel(logging.INFO)
	else:
		logger.setLevel(logging.DEBUG)
	hdlr = logging.StreamHandler()
	fmt = logging.Formatter("%(levelname)s:%(message)s")
	hdlr.setFormatter(fmt)
	logger.addHandler(hdlr)

if options.version:
	import zeroinstall
	print("0alias (zero-install) " + zeroinstall.version)
	print("Copyright (C) 2010 Thomas Leonard")
	print("This program comes with ABSOLUTELY NO WARRANTY,")
	print("to the extent permitted by law.")
	print("You may redistribute copies of this program")
	print("under the terms of the GNU Lesser General Public License.")
	print("For more information about these matters, see the file named COPYING.")
	sys.exit(0)

if options.manpage:
	print(_('ERROR: "0alias --manpage" has been removed; use "0install man" instead'), file = sys.stderr)
elif len(args) == 0:
	print(_('ERROR: "0alias" has been removed; use "0install add" instead'), file = sys.stderr)
elif len(args) == 1:
	print(_('ERROR: "0alias" has been removed; use "0install update" instead:\n0install update alias:%s') % args[0], file = sys.stderr)
else:
	print(_('ERROR: "0alias" has been removed; use "0install add" instead:\n0install add %s %s') % (args[0], args[1]), file = sys.stderr)
sys.exit(1)
