<filename>dfetch/commands/update.py
"""Update is the main functionality of dfetch.

You can add Projects to your :ref:`Manifest` and update will fetch the version specified.
It tries to determine what kind of vcs it is: git, svn or something else.
"""

import argparse
import os

import dfetch.commands.command
import dfetch.manifest.manifest
import dfetch.manifest.project
import dfetch.manifest.validate
import dfetch.project.git
import dfetch.project.svn
from dfetch.log import get_logger

logger = get_logger(__name__)


class Update(dfetch.commands.command.Command):
    """Update all modules from the manifest.

    Verifies the manifest and checks all dependencies if updates are available.
    """

    @staticmethod
    def create_menu(subparsers: "argparse._SubParsersAction") -> None:
        """Add the menu for the update action."""
        parser = dfetch.commands.command.Command.parser(subparsers, Update)
        parser.add_argument("--dry-run", "-n", action="store_true", help="Only check")

    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the update."""
        manifest, path = dfetch.manifest.manifest.get_manifest()

        with dfetch.util.util.in_directory(os.path.dirname(path)):
            exceptions = []
            for project in manifest.projects:
                try:
                    dfetch.project.make(project).update()
                except RuntimeError as exc:
                    exceptions += [str(exc)]

        if exceptions:
            raise RuntimeError("\n".join(exceptions))

<filename>dfetch/commands/update.py
"""Update is the main functionality of dfetch.

You can add Projects to your :ref:`Manifest` and update will fetch the version specified.
It tries to determine what kind of vcs it is: git, svn or something else.
"""

import argparse
import os

import dfetch.commands.command
import dfetch.manifest.manifest
import dfetch.manifest.project
import dfetch.manifest.validate
import dfetch.project.git
import dfetch.project.svn
from dfetch.log import get_logger

logger = get_logger(__name__)


class Update(dfetch.commands.command.Command):
    """Update all modules from the manifest.

    Verifies the manifest and checks all dependencies if updates are available.
    """

    @staticmethod
    def create_menu(subparsers: "argparse._SubParsersAction") -> None:
        """Add the menu for the update action."""
        parser = dfetch.commands.command.Command.parser(subparsers, Update)
        parser.add_argument("--dry-run", "-n", action="store_true", help="Only check")

    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the update."""
        manifest, path = dfetch.manifest.manifest.get_manifest()

        with dfetch.util.util.in_directory(os.path.dirname(path)):
            exceptions = []
            for project in manifest.projects:
                try:
                    dfetch.project.make(project).update()
                except RuntimeError as exc:
                    exceptions += [str(exc)]

        if exceptions:
            raise RuntimeError("\n".join(exceptions))

Update is the main functionality of dfetch.  You can add Projects to your :ref:`Manifest` and update will fetch the version specified. It tries to determine what kind of vcs it is: git, svn or something else. Update all modules from the manifest.      Verifies the manifest and checks all dependencies if updates are available. Add the menu for the update action. Perform the update.