Large-scale API cleanup
[zeroinstall/zeroinstall-afb.git] / zeroinstall / cmd / run.py
blob69d0c69608df02cd1b936f283c073781d12ad635
1 """
2 The B{0install run} command-line interface.
3 """
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 import sys
10 from zeroinstall import _
11 from zeroinstall.cmd import UsageError, select
12 from zeroinstall.injector import model
14 syntax = "URI [ARGS]"
16 def add_options(parser):
17 select.add_generic_select_options(parser)
18 parser.add_option("-m", "--main", help=_("name of the file to execute"))
19 parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND')
20 parser.disable_interspersed_args()
22 def handle(config, options, args):
23 if len(args) < 1:
24 raise UsageError()
25 iface_uri = model.canonical_iface_uri(args[0])
26 prog_args = args[1:]
28 def test_callback(sels):
29 from zeroinstall.injector import run
30 return run.test_selections(sels, prog_args,
31 False, # dry-run
32 options.main)
34 sels = select.get_selections(config, options, iface_uri,
35 select_only = False, download_only = False,
36 test_callback = test_callback)
37 if not sels:
38 sys.exit(1) # Aborted by user
40 from zeroinstall.injector import run
41 run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)