1 """
2 The B{0install run} command-line interface.
3 """
4
5
6
7
8 import sys
9
10 from zeroinstall import _
11 from zeroinstall.support import tasks
12 from zeroinstall.cmd import UsageError, select
13 from zeroinstall.injector import model
14
15 syntax = "URI [ARGS]"
16
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()
22
23 -def handle(config, options, args):
24 """@type config: L{zeroinstall.injector.config.Config}
25 @type args: [str]"""
26 if len(args) < 1:
27 raise UsageError()
28
29 prog_args = args[1:]
30
31 def test_callback(sels):
32 from zeroinstall.injector import run
33 return run.test_selections(sels, prog_args,
34 False,
35 options.main)
36
37 app = config.app_mgr.lookup_app(args[0], missing_ok = True)
38 if app is not None:
39 sels = app.get_selections(may_update = True, use_gui = options.gui)
40 r = app.get_requirements()
41 do_select = r.parse_update_options(options)
42 iface_uri = sels.interface
43 else:
44 iface_uri = model.canonical_iface_uri(args[0])
45 do_select = True
46
47 if do_select or options.gui:
48 sels = select.get_selections(config, options, iface_uri,
49 select_only = False, download_only = False,
50 test_callback = test_callback)
51 if not sels:
52 sys.exit(1)
53
54 from zeroinstall.injector import run
55 run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
56
58 """@type completion: L{zeroinstall.cmd._Completion}
59 @type args: [str]
60 @type cword: int"""
61 if cword == 0:
62 select.complete(completion, args, cword)
63 else:
64 completion.expand_files()
65