# Path: quilt/cli/parser.py
# class Argument(object):
# 
#     """
#     A class to declare positional arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = Argument(help="A first string argument")
#             arg2 = Argument(type=int)
#             arg3 = Argument(nargs=2)
#     """
# 
#     creation_counter = 0
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Constructs an Argument instance
# 
#         args and kwargs are passed directly to
#         argparse.ArgumentParser.add_argument
#         """
#         self.args = args
#         self.kwargs = kwargs
#         self.creation_counter = Argument.creation_counter
#         Argument.creation_counter += 1
# 
#     def _get_kwargs(self):
#         if self.args:
#             return self.kwargs
# 
#         kwargs = {"dest": self.name}
#         kwargs.update(self.kwargs)
#         return kwargs
# 
#     def _get_args(self):
#         return self.args
# 
#     def add_to_parser(self, parser):
#         """
#         Adds the argument to an argparse.ArgumentParser instance
# 
#         @param parser An argparse.ArgumentParser instance
#         """
#         kwargs = self._get_kwargs()
#         args = self._get_args()
#         parser.add_argument(*args, **kwargs)
# 
#     def set_name(self, name):
#         """
#         Sets the name of this Argument.
#         Normally this method should not be called directly.
#         It is used by the ArgumentsCollectorMetaClass.
# 
#         @param name A string for a name
#         """
#         self.name = name
# 
# class OptionArgument(Argument):
# 
#     """
#     A class to declare (optional) arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = OptionArgument(help="A first string argument")
#             arg2 = OptionArgument(type=int)
#             arg3 = OptionArgument(nargs=2)
#             arg4 = OptionArgument(required=True)
#     
#     By default, the option name is taken from the attribute name and prefixed
#     with two dashes, or one dash if the name is a single character:
#     
#     verbose = OptionArgument(action="store_true")  # usage: [--verbose]
#     v = OptionArgument(action="store_true")  # usage: [-v]
#     """
# 
#     prefix_chars = "--"
# 
#     def _get_args(self):
#         args = self.args
#         if not args:
#             if self.prefix_chars == "--" and len(self.name) == 1:
#                 args = ("-" + self.name,)
#             else:
#                 args = (self.prefix_chars + self.name,)
#         return args
# 
# Path: quilt/delete.py
# class Delete(Command):
# 
#     """Command class to delete patches
#     """
# 
#     deleting_patch = Signal()
#     deleted_patch = Signal()
# 
#     def __init__(self, cwd, quilt_pc, quilt_patches):
#         super(Delete, self).__init__(cwd)
#         self.quilt_pc = Directory(quilt_pc)
#         self.quilt_patches = Directory(quilt_patches)
#         self.db = Db(quilt_pc)
#         self.series = Series(quilt_patches)
#         self.pop = Pop(cwd, quilt_pc)
# 
#     def _delete_patch(self, patch, remove=False, backup=False):
#         if self.series.is_empty():
#             raise NoPatchesInSeries(self.series)
#         if not self.series.is_patch(patch):
#             raise UnknownPatch(self.series, patch)
# 
#         applied = self.db.top_patch() == patch
#         self.deleting_patch(patch, applied)
# 
#         if applied:
#             self.pop._unapply_patch(patch)
#             self.db = self.pop.db
#             self.db.save()
# 
#         self.series.remove_patch(patch)
#         self.series.save()
# 
#         patch_file = self.quilt_patches + File(patch.get_name())
# 
#         if remove:
#             if backup:
#                 patch_file.copy(File(patch_file.get_name() + "~"))
# 
#             patch_file.delete_if_exists()
# 
#         self.deleted_patch(patch)
# 
#     def delete_next(self, remove=False, backup=False):
#         """ Delete next unapplied patch
#         If remove is True the patch file will also be removed. If remove and
#         backup are True a copy of the deleted patch file will be made.
#         """
#         patch = self.db.top_patch()
#         if patch:
#             after = self.series.patch_after(patch)
#         else:
#             after = self.series.first_patch()
#         if not after:
#             raise QuiltError("No next patch")
# 
#         self._delete_patch(after, remove=remove, backup=backup)
# 
#     def delete_patch(self, patch_name=None, remove=False, backup=False):
#         """ Delete specified patch from the series
#         If remove is True the patch file will also be removed. If remove and
#         backup are True a copy of the deleted patch file will be made.
#         """
#         if patch_name:
#             patch = Patch(patch_name)
#         else:
#             patch = self.db.top_patch()
#             if not patch:
#                 raise NoAppliedPatch(self.db)
# 
#         self._delete_patch(patch, remove=remove, backup=backup)


from quilt.cli.meta import Command
from quilt.cli.parser import Argument, OptionArgument
from quilt.delete import Delete
# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.



class DeleteCommand(Command):

    name = "delete"
    help = "Remove the specified or topmost patch from the series file."

    remove = OptionArgument("-r", action="store_true", dest="remove",
                            default=False,
                            help="Remove the deleted patch file from the "
                            "patches directory as well.")
    backup = OptionArgument("--backup",
                            action="store_true", default=False, dest="backup",
                            help="Rename the patch file to patch~ rather than "
                            "deleting it. Ignored if not used with `-r'.")

# Path: quilt/cli/parser.py
# class Argument(object):
# 
#     """
#     A class to declare positional arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = Argument(help="A first string argument")
#             arg2 = Argument(type=int)
#             arg3 = Argument(nargs=2)
#     """
# 
#     creation_counter = 0
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Constructs an Argument instance
# 
#         args and kwargs are passed directly to
#         argparse.ArgumentParser.add_argument
#         """
#         self.args = args
#         self.kwargs = kwargs
#         self.creation_counter = Argument.creation_counter
#         Argument.creation_counter += 1
# 
#     def _get_kwargs(self):
#         if self.args:
#             return self.kwargs
# 
#         kwargs = {"dest": self.name}
#         kwargs.update(self.kwargs)
#         return kwargs
# 
#     def _get_args(self):
#         return self.args
# 
#     def add_to_parser(self, parser):
#         """
#         Adds the argument to an argparse.ArgumentParser instance
# 
#         @param parser An argparse.ArgumentParser instance
#         """
#         kwargs = self._get_kwargs()
#         args = self._get_args()
#         parser.add_argument(*args, **kwargs)
# 
#     def set_name(self, name):
#         """
#         Sets the name of this Argument.
#         Normally this method should not be called directly.
#         It is used by the ArgumentsCollectorMetaClass.
# 
#         @param name A string for a name
#         """
#         self.name = name
# 
# class OptionArgument(Argument):
# 
#     """
#     A class to declare (optional) arguments at a class
# 
#     Usage:
#         class MyParser(Parser):
# 
#             arg1 = OptionArgument(help="A first string argument")
#             arg2 = OptionArgument(type=int)
#             arg3 = OptionArgument(nargs=2)
#             arg4 = OptionArgument(required=True)
#     
#     By default, the option name is taken from the attribute name and prefixed
#     with two dashes, or one dash if the name is a single character:
#     
#     verbose = OptionArgument(action="store_true")  # usage: [--verbose]
#     v = OptionArgument(action="store_true")  # usage: [-v]
#     """
# 
#     prefix_chars = "--"
# 
#     def _get_args(self):
#         args = self.args
#         if not args:
#             if self.prefix_chars == "--" and len(self.name) == 1:
#                 args = ("-" + self.name,)
#             else:
#                 args = (self.prefix_chars + self.name,)
#         return args
# 
# Path: quilt/delete.py
# class Delete(Command):
# 
#     """Command class to delete patches
#     """
# 
#     deleting_patch = Signal()
#     deleted_patch = Signal()
# 
#     def __init__(self, cwd, quilt_pc, quilt_patches):
#         super(Delete, self).__init__(cwd)
#         self.quilt_pc = Directory(quilt_pc)
#         self.quilt_patches = Directory(quilt_patches)
#         self.db = Db(quilt_pc)
#         self.series = Series(quilt_patches)
#         self.pop = Pop(cwd, quilt_pc)
# 
#     def _delete_patch(self, patch, remove=False, backup=False):
#         if self.series.is_empty():
#             raise NoPatchesInSeries(self.series)
#         if not self.series.is_patch(patch):
#             raise UnknownPatch(self.series, patch)
# 
#         applied = self.db.top_patch() == patch
#         self.deleting_patch(patch, applied)
# 
#         if applied:
#             self.pop._unapply_patch(patch)
#             self.db = self.pop.db
#             self.db.save()
# 
#         self.series.remove_patch(patch)
#         self.series.save()
# 
#         patch_file = self.quilt_patches + File(patch.get_name())
# 
#         if remove:
#             if backup:
#                 patch_file.copy(File(patch_file.get_name() + "~"))
# 
#             patch_file.delete_if_exists()
# 
#         self.deleted_patch(patch)
# 
#     def delete_next(self, remove=False, backup=False):
#         """ Delete next unapplied patch
#         If remove is True the patch file will also be removed. If remove and
#         backup are True a copy of the deleted patch file will be made.
#         """
#         patch = self.db.top_patch()
#         if patch:
#             after = self.series.patch_after(patch)
#         else:
#             after = self.series.first_patch()
#         if not after:
#             raise QuiltError("No next patch")
# 
#         self._delete_patch(after, remove=remove, backup=backup)
# 
#     def delete_patch(self, patch_name=None, remove=False, backup=False):
#         """ Delete specified patch from the series
#         If remove is True the patch file will also be removed. If remove and
#         backup are True a copy of the deleted patch file will be made.
#         """
#         if patch_name:
#             patch = Patch(patch_name)
#         else:
#             patch = self.db.top_patch()
#             if not patch:
#                 raise NoAppliedPatch(self.db)
# 
#         self._delete_patch(patch, remove=remove, backup=backup)


# Path: quilt/cli/delete.py
from quilt.cli.meta import Command
from quilt.cli.parser import Argument, OptionArgument
from quilt.delete import Delete

# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.



class DeleteCommand(Command):

    name = "delete"
    help = "Remove the specified or topmost patch from the series file."

    remove = OptionArgument("-r", action="store_true", dest="remove",
                            default=False,
                            help="Remove the deleted patch file from the "
                            "patches directory as well.")
    backup = OptionArgument("--backup",
                            action="store_true", default=False, dest="backup",
                            help="Rename the patch file to patch~ rather than "
                            "deleting it. Ignored if not used with `-r'.")

    next = OptionArgument("-n", action="store_true", dest="next",