159
163
s.shelve(source, all, message)
167
# The following classes are only used as subcommands for 'shelf', they're
168
# not to be registered directly with bzr.
170
class cmd_shelf_list(bzrlib.commands.Command):
171
"""List the patches on the current shelf."""
172
aliases = ['list', 'ls']
177
class cmd_shelf_delete(bzrlib.commands.Command):
178
"""Delete the patch from the current shelf."""
179
aliases = ['delete', 'del']
180
takes_args = ['patch']
181
def run(self, patch):
182
self.shelf.delete(patch)
185
class cmd_shelf_switch(bzrlib.commands.Command):
186
"""Switch to the other shelf, create it if necessary."""
188
takes_args = ['othershelf']
189
def run(self, othershelf):
190
s = Shelf(self.shelf.base, othershelf)
194
class cmd_shelf_show(bzrlib.commands.Command):
195
"""Show the contents of the specified or topmost patch."""
196
aliases = ['show', 'cat', 'display']
197
takes_args = ['patch?']
198
def run(self, patch=None):
199
self.shelf.display(patch)
202
class cmd_shelf_upgrade(bzrlib.commands.Command):
203
"""Upgrade old format shelves."""
204
aliases = ['upgrade']
162
209
class cmd_shelf(bzrlib.commands.Command):
163
"""Perform various operations on your shelved patches. See also shelve.
166
list (ls) List the patches on the current shelf.
167
delete (del) <patch> Delete a patch from the current shelf.
168
switch <shelf> Switch to the named shelf, create it if necessary.
169
show <patch> Show the contents of the specified patch.
170
upgrade Upgrade old format shelves.
210
"""Perform various operations on your shelved patches. See also shelve."""
172
211
takes_args = ['subcommand', 'args*']
213
subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
214
cmd_shelf_show, cmd_shelf_upgrade]
174
216
def run(self, subcommand, args_list):
219
cmd = self._get_cmd_object(subcommand)
177
220
source = BzrPatchSource()
178
221
s = Shelf(source.base)
180
if subcommand == 'ls' or subcommand == 'list':
181
self.__check_no_args(args_list, "shelf list takes no arguments!")
183
elif subcommand == 'delete' or subcommand == 'del':
184
self.__check_one_arg(args_list, "shelf delete takes one argument!")
185
s.delete(args_list[0])
186
elif subcommand == 'switch':
187
self.__check_one_arg(args_list, "shelf switch takes one argument!")
188
s = Shelf(source.base, args_list[0])
190
elif subcommand == 'show':
191
self.__check_one_arg(args_list, "shelf show takes one argument!")
192
s.display(args_list[0])
193
elif subcommand == 'upgrade':
194
self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
197
raise CommandError("Unknown shelf subcommand '%s'" % subcommand)
199
def __check_one_arg(self, args, msg):
200
if args is None or len(args) != 1:
201
raise CommandError(msg)
203
def __check_no_args(self, args, msg):
205
raise CommandError(msg)
223
return cmd.run_argv_aliases(args_list)
225
def _get_cmd_object(self, cmd_name):
226
for cmd_class in self.subcommands:
227
for alias in cmd_class.aliases:
228
if alias == cmd_name:
230
raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
233
text = ["%s\n\nSubcommands:\n" % self.__doc__]
235
for cmd_class in self.subcommands:
236
text.extend(self.sub_help(cmd_class) + ['\n'])
240
def sub_help(self, cmd_class):
242
cmd_obj = cmd_class()
245
usage = command_usage(cmd_obj)
246
usage = usage.replace('bzr shelf-', '')
247
text.append('%s%s\n' % (indent, usage))
249
text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
251
# Somewhat copied from bzrlib.help.help_on_command_options
253
for option_name, option in sorted(cmd_obj.options().items()):
254
if option_name == 'help':
256
option_help.append('%s--%s' % (3 * indent, option_name))
257
if option.type is not None:
258
option_help.append(' %s' % option.argname.upper())
259
if option.short_name():
260
option_help.append(', -%s' % option.short_name())
261
option_help.append('%s%s\n' % (2 * indent, option.help))
263
if len(option_help) > 0:
264
text.append('%soptions:\n' % (2 * indent))
265
text.extend(option_help)
208
271
class cmd_unshelve(bzrlib.commands.Command):
209
"""Restore the most recently shelved changes to current tree. <BZRTOOLS>
272
"""Restore shelved changes. <BZRTOOLS>
274
By default the most recently shelved changes are restored. However if you
275
specify a patch by name those changes will be restored instead.
210
277
See 'shelve' for more information.
212
279
takes_options = [
213
280
Option('all', help='Unshelve all changes without prompting'),
214
281
Option('force', help='Force unshelving even if errors occur'),
216
def run(self, all=False, force=False):
283
takes_args = ['patch?']
284
def run(self, patch=None, all=False, force=False):
217
285
source = BzrPatchSource()
218
286
s = Shelf(source.base)
219
s.unshelve(source, all, force)
287
s.unshelve(source, patch, all, force)