1from __future__ import unicode_literals
2
3import dvc.prompt as prompt
4import dvc.logger as logger
5from dvc.command.base import CmdBase
6from dvc.exceptions import DvcException
7
8
9class CmdDestroy(CmdBase):
10    def run_cmd(self):
11        try:
12            statement = (
13                "This will destroy all information about your pipelines,"
14                " all data files, as well as cache in .dvc/cache."
15                "\n"
16                "Are you sure you want to continue?"
17            )
18
19            if not self.args.force and not prompt.confirm(statement):
20                raise DvcException(
21                    "cannot destroy without a confirmation from the user."
22                    " Use '-f' to force."
23                )
24
25            self.repo.destroy()
26        except Exception:
27            logger.error("failed to destroy DVC")
28            return 1
29        return 0
30
31
32def add_parser(subparsers, parent_parser):
33    DESTROY_HELP = (
34        "Destroy dvc. Will remove all repo's information, "
35        "data files and cache."
36    )
37    destroy_parser = subparsers.add_parser(
38        "destroy",
39        parents=[parent_parser],
40        description=DESTROY_HELP,
41        help=DESTROY_HELP,
42    )
43    destroy_parser.add_argument(
44        "-f",
45        "--force",
46        action="store_true",
47        default=False,
48        help="Force destruction.",
49    )
50    destroy_parser.set_defaults(func=CmdDestroy)
51