Reselect when using "0install run -g APP" or with extra requirements
[zeroinstall/solver.git] / zeroinstall / cmd / run.py
blob0b3ccd1430ae36c4a9ffb6ebdef97b839d32a94b
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.support import tasks
12 from zeroinstall.cmd import UsageError, select
13 from zeroinstall.injector import model
15 syntax = "URI [ARGS]"
17 def add_options(parser):
18 select.add_generic_select_options(parser)
19 parser.add_option("-m", "--main", help=_("name of the file to execute"))
20 parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND')
21 parser.disable_interspersed_args()
23 def handle(config, options, args):
24 if len(args) < 1:
25 raise UsageError()
27 prog_args = args[1:]
29 def test_callback(sels):
30 from zeroinstall.injector import run
31 return run.test_selections(sels, prog_args,
32 False, # dry-run
33 options.main)
35 app = config.app_mgr.lookup_app(args[0], missing_ok = True)
36 if app is not None:
37 sels = app.get_selections()
38 r = app.get_requirements()
39 do_select = r.parse_update_options(options)
40 iface_uri = sels.interface
41 else:
42 iface_uri = model.canonical_iface_uri(args[0])
43 do_select = True
45 if do_select or options.gui:
46 sels = select.get_selections(config, options, iface_uri,
47 select_only = False, download_only = False,
48 test_callback = test_callback)
49 if not sels:
50 sys.exit(1) # Aborted by user
51 else:
52 dl = app.download_selections(sels)
53 if dl:
54 tasks.wait_for_blocker(dl)
55 tasks.check(dl)
57 from zeroinstall.injector import run
58 run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)