root/trunk/twisted/conch/client/options.py

Revision 32921, 3.8 KB (checked in by teratorn, 7 months ago)

Merge make-zshcomp-dynamic-3078-6: New tab-completion system
Author: teratorn
Reviewer: glyph, exarkun
Fixes: #3078

Deprecates t.p.zshcomp in favor of a tab-completion system in t.p.usage - completion matches are generated dynamically at tab-press time.

Line 
1# Copyright (c) Twisted Matrix Laboratories.
2# See LICENSE for details.
3
4#
5from twisted.conch.ssh.transport import SSHClientTransport, SSHCiphers
6from twisted.python import usage
7
8import sys
9
10class ConchOptions(usage.Options):
11
12    optParameters = [['user', 'l', None, 'Log in using this user name.'],
13                     ['identity', 'i', None],
14                     ['ciphers', 'c', None],
15                     ['macs', 'm', None],
16                     ['port', 'p', None, 'Connect to this port.  Server must be on the same port.'],
17                     ['option', 'o', None, 'Ignored OpenSSH options'],
18                     ['host-key-algorithms', '', None],
19                     ['known-hosts', '', None, 'File to check for host keys'],
20                     ['user-authentications', '', None, 'Types of user authentications to use.'],
21                     ['logfile', '', None, 'File to log to, or - for stdout'],
22                   ]
23
24    optFlags = [['version', 'V', 'Display version number only.'],
25                ['compress', 'C', 'Enable compression.'],
26                ['log', 'v', 'Enable logging (defaults to stderr)'],
27                ['nox11', 'x', 'Disable X11 connection forwarding (default)'],
28                ['agent', 'A', 'Enable authentication agent forwarding'],
29                ['noagent', 'a', 'Disable authentication agent forwarding (default)'],
30                ['reconnect', 'r', 'Reconnect to the server if the connection is lost.'],
31               ]
32
33    compData = usage.Completions(
34        mutuallyExclusive=[("agent", "noagent")],
35        optActions={
36            "user": usage.CompleteUsernames(),
37            "ciphers": usage.CompleteMultiList(
38                SSHCiphers.cipherMap.keys(),
39                descr='ciphers to choose from'),
40            "macs": usage.CompleteMultiList(
41                SSHCiphers.macMap.keys(),
42                descr='macs to choose from'),
43            "host-key-algorithms": usage.CompleteMultiList(
44                SSHClientTransport.supportedPublicKeys,
45                descr='host key algorithms to choose from'),
46            #"user-authentications": usage.CompleteMultiList(?
47            # descr='user authentication types' ),
48            },
49        extraActions=[usage.CompleteUserAtHost(),
50                      usage.Completer(descr="command"),
51                      usage.Completer(descr='argument',
52                                      repeat=True)]
53        )
54
55    def __init__(self, *args, **kw):
56        usage.Options.__init__(self, *args, **kw)
57        self.identitys = []
58        self.conns = None
59
60    def opt_identity(self, i):
61        """Identity for public-key authentication"""
62        self.identitys.append(i)
63
64    def opt_ciphers(self, ciphers):
65        "Select encryption algorithms"
66        ciphers = ciphers.split(',')
67        for cipher in ciphers:
68            if not SSHCiphers.cipherMap.has_key(cipher):
69                sys.exit("Unknown cipher type '%s'" % cipher)
70        self['ciphers'] = ciphers
71
72
73    def opt_macs(self, macs):
74        "Specify MAC algorithms"
75        macs = macs.split(',')
76        for mac in macs:
77            if not SSHCiphers.macMap.has_key(mac):
78                sys.exit("Unknown mac type '%s'" % mac)
79        self['macs'] = macs
80
81    def opt_host_key_algorithms(self, hkas):
82        "Select host key algorithms"
83        hkas = hkas.split(',')
84        for hka in hkas:
85            if hka not in SSHClientTransport.supportedPublicKeys:
86                sys.exit("Unknown host key type '%s'" % hka)
87        self['host-key-algorithms'] = hkas
88
89    def opt_user_authentications(self, uas):
90        "Choose how to authenticate to the remote server"
91        self['user-authentications'] = uas.split(',')
92
93#    def opt_compress(self):
94#        "Enable compression"
95#        self.enableCompression = 1
96#        SSHClientTransport.supportedCompressions[0:1] = ['zlib']
Note: See TracBrowser for help on using the browser.