1from __future__ import unicode_literals
2
3from dvc.command.base import CmdBase
4
5
6class CmdCheckout(CmdBase):
7    def run(self):
8        if not self.args.targets:
9            self.repo.checkout(force=self.args.force)
10        else:
11            for target in self.args.targets:
12                self.repo.checkout(
13                    target=target,
14                    with_deps=self.args.with_deps,
15                    force=self.args.force,
16                )
17        return 0
18
19
20def add_parser(subparsers, parent_parser):
21    CHECKOUT_HELP = "Checkout data files from cache."
22    checkout_parser = subparsers.add_parser(
23        "checkout",
24        parents=[parent_parser],
25        description=CHECKOUT_HELP,
26        help=CHECKOUT_HELP,
27    )
28    checkout_parser.add_argument(
29        "-d",
30        "--with-deps",
31        action="store_true",
32        default=False,
33        help="Checkout all dependencies of the specified target.",
34    )
35    checkout_parser.add_argument(
36        "-f",
37        "--force",
38        action="store_true",
39        default=False,
40        help="Do not prompt when removing working directory files.",
41    )
42    checkout_parser.add_argument("targets", nargs="*", help="DVC files.")
43    checkout_parser.set_defaults(func=CmdCheckout)
44