21
21
from bzrlib import (
30
28
from bzrlib.commands import Command
31
from bzrlib.option import Option, RegistryOption
29
from bzrlib.option import Option
34
32
def _parse_version_info_format(format):
49
47
class cmd_version_info(Command):
50
"""Show version information about this tree.
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.
58
bzr version-info --custom \\
59
--template="#define VERSION_INFO \\"Project 1.2.3 (r{revno})\\"\\n"
61
will produce a C header file with formatted string containing the
62
current revision number. Other supported variables in templates are:
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,
73
takes_options = [RegistryOption('format',
74
'Select the output format.',
75
version_info_formats.format_registry,
48
"""Show version information about this tree."""
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.')
85
59
takes_args = ['location?']
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):
93
67
if location is None:
97
format = version_info_formats.format_registry.get()
71
format = version_info_formats.get_builder(None)
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,
89
include_file_revisions=include_file_revisions)
117
90
builder.generate(self.outf)