diff --git a/dfetch/commands/check.py b/dfetch/commands/check.py index c772f037..49de5284 100644 --- a/dfetch/commands/check.py +++ b/dfetch/commands/check.py @@ -48,6 +48,13 @@ def create_menu(subparsers: "argparse._SubParsersAction") -> None: action="store_true", help="Don't recursively check for child manifests.", ) + parser.add_argument( + "projects", + metavar="", + type=str, + nargs="*", + help="Specific project(s) to check", + ) def __call__(self, args: argparse.Namespace) -> None: """Perform the check.""" @@ -55,7 +62,12 @@ def __call__(self, args: argparse.Namespace) -> None: with in_directory(os.path.dirname(path)): exceptions: List[str] = [] - for project in manifest.projects: + projects = manifest.selected_projects(args.projects) + if not projects: + raise RuntimeError( + f"No (such) projects found! {', '.join(args.projects)}" + ) + for project in projects: with catch_runtime_exceptions(exceptions) as exceptions: dfetch.project.make(project).check_for_update() diff --git a/dfetch/manifest/manifest.py b/dfetch/manifest/manifest.py index a60cc2be..f0b9850c 100644 --- a/dfetch/manifest/manifest.py +++ b/dfetch/manifest/manifest.py @@ -172,6 +172,16 @@ def projects(self) -> Sequence[ProjectEntry]: """Get a list of Projects from the manifest.""" return list(self._projects.values()) + def selected_projects(self, names: Sequence[str]) -> Sequence[ProjectEntry]: + """Get a list of Projects from the manifest with the given names.""" + return ( + list( + project for project in self._projects.values() if project.name in names + ) + if names + else list(self._projects.values()) + ) + @property def remotes(self) -> Sequence[Remote]: """Get a list of Remotes from the manifest.""" diff --git a/features/check-specific-projects.feature b/features/check-specific-projects.feature new file mode 100644 index 00000000..042256f7 --- /dev/null +++ b/features/check-specific-projects.feature @@ -0,0 +1,32 @@ +Feature: Checking specific projects + + *DFetch* can check specific projects, this is usefull when you have a lot + of projects in your manifest. + + Scenario: Single project is checked + Given the manifest 'dfetch.yaml' + """ + manifest: + version: '0.0' + + remotes: + - name: github-com-dfetch-org + url-base: https://github.com/dfetch-org/test-repo + + projects: + - name: ext/test-repo-rev-only + revision: e1fda19a57b873eb8e6ae37780594cbb77b70f1a + dst: ext/test-repo-rev-only + + - name: ext/test-rev-and-branch + revision: 8df389d0524863b85f484f15a91c5f2c40aefda1 + branch: main + dst: ext/test-rev-and-branch + + """ + When I run "dfetch check ext/test-rev-and-branch" + Then the output shows + """ + Dfetch (0.2.0) + ext/test-rev-and-branch: wanted (main - 8df389d0524863b85f484f15a91c5f2c40aefda1), available (main - e1fda19a57b873eb8e6ae37780594cbb77b70f1a) + """