In unit-tests, always use StringIO, not io
[zeroinstall.git] / zeroinstall / cmd / add.py
blob70afca4be31af311ebad9f69c0338e03e0f2c97a
1 """
2 The B{0install add} command-line interface.
3 """
5 # Copyright (C) 2012, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 from __future__ import print_function
10 import sys
12 from zeroinstall.cmd import UsageError, select
13 from zeroinstall.injector import model, requirements
15 syntax = "PET-NAME INTERFACE"
17 def add_options(parser):
18 select.add_options(parser)
20 def handle(config, options, args):
21 if len(args) != 2:
22 raise UsageError()
24 pet_name = args[0]
25 iface_uri = model.canonical_iface_uri(args[1])
27 sels = select.get_selections(config, options, iface_uri, select_only = False, download_only = True, test_callback = None)
28 if not sels:
29 sys.exit(1) # Aborted by user
31 r = requirements.Requirements(iface_uri)
32 r.parse_options(options)
34 app = config.app_mgr.create_app(pet_name, r)
35 app.set_selections(sels)
36 app.integrate_shell(pet_name)