51
52
s.shelve(source, all, message)
56
# The following classes are only used as subcommands for 'shelf', they're
57
# not to be registered directly with bzr.
59
class cmd_shelf_list(bzrlib.commands.Command):
60
"""List the patches on the current shelf."""
61
aliases = ['list', 'ls']
66
class cmd_shelf_delete(bzrlib.commands.Command):
67
"""Delete the patch from the current shelf."""
68
aliases = ['delete', 'del']
69
takes_args = ['patch']
71
self.shelf.delete(patch)
74
class cmd_shelf_switch(bzrlib.commands.Command):
75
"""Switch to the other shelf, create it if necessary."""
77
takes_args = ['other-shelf']
78
def run(self, other_shelf):
79
s = Shelf(self.shelf.base, other_shelf)
83
class cmd_shelf_show(bzrlib.commands.Command):
84
"""Show the contents of the specified patch."""
85
aliases = ['show', 'cat', 'display']
86
takes_args = ['patch']
88
self.shelf.display(patch)
91
class cmd_shelf_upgrade(bzrlib.commands.Command):
92
"""Upgrade old format shelves."""
54
98
class cmd_shelf(bzrlib.commands.Command):
55
"""Perform various operations on your shelved patches. See also shelve.
58
list (ls) List the patches on the current shelf.
59
delete (del) <patch> Delete a patch from the current shelf.
60
switch <shelf> Switch to the named shelf, create it if necessary.
61
show <patch> Show the contents of the specified patch.
62
upgrade Upgrade old format shelves.
99
"""Perform various operations on your shelved patches. See also shelve."""
64
100
takes_args = ['subcommand', 'args*']
102
subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
103
cmd_shelf_show, cmd_shelf_upgrade]
66
105
def run(self, subcommand, args_list):
108
cmd = self._get_cmd_object(subcommand)
69
109
source = BzrPatchSource()
70
110
s = Shelf(source.base)
72
if subcommand == 'ls' or subcommand == 'list':
73
self.__check_no_args(args_list, "shelf list takes no arguments!")
75
elif subcommand == 'delete' or subcommand == 'del':
76
self.__check_one_arg(args_list, "shelf delete takes one argument!")
77
s.delete(args_list[0])
78
elif subcommand == 'switch':
79
self.__check_one_arg(args_list, "shelf switch takes one argument!")
80
s = Shelf(source.base, args_list[0])
82
elif subcommand == 'show':
83
self.__check_one_arg(args_list, "shelf show takes one argument!")
84
s.display(args_list[0])
85
elif subcommand == 'upgrade':
86
self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
89
raise CommandError("Unknown shelf subcommand '%s'" % subcommand)
91
def __check_one_arg(self, args, msg):
92
if args is None or len(args) != 1:
93
raise CommandError(msg)
95
def __check_no_args(self, args, msg):
97
raise CommandError(msg)
112
return cmd.run_argv_aliases(args_list)
114
def _get_cmd_object(self, cmd_name):
115
for cmd_class in self.subcommands:
116
for alias in cmd_class.aliases:
117
if alias == cmd_name:
119
raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
122
lines = ["%s\n\nSubcommands:" % self.__doc__]
126
for cmd_class in self.subcommands:
127
usage = command_usage(cmd_class())
128
usage = usage.replace('bzr shelf-', '')
129
sub_help.append((usage, cmd_class.__doc__))
130
maxlen = max(maxlen, len(usage))
132
for usage, doc in sub_help:
133
lines.append(" %-*s %s" % (maxlen, usage, doc))
135
return '\n'.join(lines)
99
138
class cmd_unshelve(bzrlib.commands.Command):
100
139
"""Restore the most recently shelved changes to the current tree.