Added '0install run' sub-command
[zeroinstall/zeroinstall-afb.git] / zeroinstall / cmd / run.py
blob5ab9d77105d29cf5ae6c04aca081ee32336c6ca4
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 from optparse import OptionParser
9 import os, sys
10 import logging
12 from zeroinstall import cmd, SafeException, _
13 from zeroinstall.cmd import UsageError, select
14 from zeroinstall.injector import model, autopolicy, selections, handler
15 from zeroinstall.injector.iface_cache import iface_cache
17 syntax = "URI [ARGS]"
19 def add_options(parser):
20 select.add_generic_select_options(parser)
21 parser.add_option("-m", "--main", help=_("name of the file to execute"))
22 parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND')
23 parser.disable_interspersed_args()
25 def handle(options, args):
26 if len(args) < 1:
27 raise UsageError()
28 iface_uri = model.canonical_iface_uri(args[0])
29 prog_args = args[1:]
31 def test_callback(sels):
32 from zeroinstall.injector import run
33 return run.test_selections(sels, prog_args,
34 False, # dry-run
35 options.main)
37 sels = select.get_selections(options, iface_uri,
38 select_only = False, download_only = False,
39 test_callback = test_callback)
40 if not sels:
41 sys.exit(1) # Aborted by user
43 from zeroinstall.injector import run
44 run.execute_selections(sels, prog_args, main = options.main, wrapper = options.wrapper)