/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/shellcomplete.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
1
17
import sys
2
18
 
3
19
 
4
 
def shellcomplete(context=None, outfile = None):
5
 
    if outfile == None:
 
20
def shellcomplete(context=None, outfile=None):
 
21
    if outfile is None:
6
22
        outfile = sys.stdout
7
 
    if context == None:
8
 
        shellcomplete_commands(outfile = outfile)
 
23
    if context is None:
 
24
        shellcomplete_commands(outfile=outfile)
9
25
    else:
10
 
        shellcomplete_on_command(context, outfile = outfile)
11
 
 
12
 
def shellcomplete_on_command(cmdname, outfile = None):
 
26
        shellcomplete_on_command(context, outfile=outfile)
 
27
 
 
28
 
 
29
def shellcomplete_on_command(cmdname, outfile=None):
13
30
    cmdname = str(cmdname)
14
31
 
15
 
    if outfile == None:
 
32
    if outfile is None:
16
33
        outfile = sys.stdout
17
34
 
18
35
    from inspect import getdoc
19
 
    import commands
 
36
    from . import commands
20
37
    cmdobj = commands.get_cmd_object(cmdname)
21
38
 
22
39
    doc = getdoc(cmdobj)
23
 
    if doc == None:
24
 
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
 
40
    if doc is None:
 
41
        raise NotImplementedError(
 
42
            "sorry, no detailed shellcomplete yet for %r" % cmdname)
25
43
 
26
 
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
 
44
    shellcomplete_on_options(cmdobj.options().values(), outfile=outfile)
27
45
    for aname in cmdobj.takes_args:
28
46
        outfile.write(aname + '\n')
29
47
 
30
48
 
31
 
def shellcomplete_on_option(options, outfile = None):
32
 
    import commands
33
 
    
34
 
    if not options:
35
 
        return
36
 
    
37
 
    if outfile == None:
38
 
        outfile = sys.stdout
39
 
 
40
 
    for on in options:
41
 
        for shortname, longname in commands.SHORT_OPTIONS.items():
42
 
            if longname == on:
43
 
                l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
44
 
                break
45
 
            else:
46
 
                l = '--' + on
47
 
        outfile.write(l + '\n')
48
 
 
49
 
 
50
 
def shellcomplete_commands(outfile = None):
 
49
def shellcomplete_on_options(options, outfile=None):
 
50
    for opt in options:
 
51
        short_name = opt.short_name()
 
52
        if short_name:
 
53
            outfile.write('"(--%s -%s)"{--%s,-%s}\n'
 
54
                          % (opt.name, short_name, opt.name, short_name))
 
55
        else:
 
56
            outfile.write('--%s\n' % opt.name)
 
57
 
 
58
 
 
59
def shellcomplete_commands(outfile=None):
51
60
    """List all commands"""
52
 
    import inspect
53
 
    import commands
 
61
    from . import commands
54
62
    from inspect import getdoc
55
 
    
56
 
    if outfile == None:
 
63
 
 
64
    commands.install_bzr_command_hooks()
 
65
 
 
66
    if outfile is None:
57
67
        outfile = sys.stdout
58
 
    
 
68
 
59
69
    cmds = []
60
 
    for cmdname, cmdclass in commands.get_all_cmds():
61
 
        cmds.append((cmdname, cmdclass))
62
 
        for alias in cmdclass.aliases:
63
 
            cmds.append((alias, cmdclass))
 
70
    for cmdname in commands.all_command_names():
 
71
        cmd = commands.get_cmd_object(cmdname)
 
72
        cmds.append((cmdname, cmd))
 
73
        for alias in cmd.aliases:
 
74
            cmds.append((alias, cmd))
64
75
    cmds.sort()
65
 
    for cmdname, cmdclass in cmds:
66
 
        if cmdclass.hidden:
 
76
    for cmdname, cmd in cmds:
 
77
        if cmd.hidden:
67
78
            continue
68
 
        doc = getdoc(cmdclass)
69
 
        if doc == None:
70
 
            outfile.write(cmdname + '\n')
 
79
        doc = getdoc(cmd)
 
80
        if doc is None:
 
81
            outfile.write(cmdname + '\n')
71
82
        else:
72
 
            doclines = doc.splitlines()
73
 
            firstline = doclines[0].lower()
74
 
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')
 
83
            doclines = doc.splitlines()
 
84
            firstline = doclines[0].lower()
 
85
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')