~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cmd_version_info.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-04 18:51:39 UTC
  • mfrom: (2961.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071104185139-kaio3sneodg2kp71
Authentication ring implementation (read-only)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib import (
22
22
    branch,
23
23
    errors,
 
24
    version_info_formats,
24
25
    workingtree,
25
26
    )
26
27
""")
27
 
from bzrlib import (
28
 
    version_info_formats,
29
 
    )
30
28
from bzrlib.commands import Command
31
 
from bzrlib.option import Option, RegistryOption
 
29
from bzrlib.option import Option
32
30
 
33
31
 
34
32
def _parse_version_info_format(format):
47
45
 
48
46
 
49
47
class cmd_version_info(Command):
50
 
    """Show version information about this tree.
51
 
 
52
 
    You can use this command to add information about version into
53
 
    source code of an application. The output can be in one of the
54
 
    supported formats or in a custom format based on a template.
55
 
 
56
 
    For example::
57
 
 
58
 
      bzr version-info --custom \\
59
 
        --template="#define VERSION_INFO \\"Project 1.2.3 (r{revno})\\"\\n"
60
 
 
61
 
    will produce a C header file with formatted string containing the
62
 
    current revision number. Other supported variables in templates are:
63
 
 
64
 
      * {date} - date of the last revision
65
 
      * {build_date} - current date
66
 
      * {revno} - revision number
67
 
      * {revision_id} - revision id
68
 
      * {branch_nick} - branch nickname
69
 
      * {clean} - 0 if the source tree contains uncommitted changes,
70
 
                  otherwise 1
71
 
    """
72
 
 
73
 
    takes_options = [RegistryOption('format',
74
 
                            'Select the output format.',
75
 
                            version_info_formats.format_registry,
76
 
                            value_switches=True),
 
48
    """Show version information about this tree."""
 
49
 
 
50
    takes_options = [Option('format', type=_parse_version_info_format,
 
51
                            help='Select the output format.'),
77
52
                     Option('all', help='Include all possible information.'),
78
53
                     Option('check-clean', help='Check if tree is clean.'),
79
54
                     Option('include-history',
80
55
                            help='Include the revision-history.'),
81
56
                     Option('include-file-revisions',
82
 
                            help='Include the last revision for each file.'),
83
 
                     Option('template', type=str, help='Template for the output.'),
 
57
                            help='Include the last revision for each file.')
84
58
                     ]
85
59
    takes_args = ['location?']
86
60
 
88
62
 
89
63
    def run(self, location=None, format=None,
90
64
            all=False, check_clean=False, include_history=False,
91
 
            include_file_revisions=False, template=None):
 
65
            include_file_revisions=False):
92
66
 
93
67
        if location is None:
94
68
            location = '.'
95
69
 
96
70
        if format is None:
97
 
            format = version_info_formats.format_registry.get()
 
71
            format = version_info_formats.get_builder(None)
98
72
 
99
73
        wt = None
100
74
        try:
104
78
        else:
105
79
            b = wt.branch
106
80
 
107
 
        if all or template:
 
81
        if all:
108
82
            include_history = True
109
83
            check_clean = True
110
84
            include_file_revisions=True
112
86
        builder = format(b, working_tree=wt,
113
87
                check_for_clean=check_clean,
114
88
                include_revision_history=include_history,
115
 
                include_file_revisions=include_file_revisions,
116
 
                template=template)
 
89
                include_file_revisions=include_file_revisions)
117
90
        builder.generate(self.outf)