1pub mod cargo;
3
4use crate::errors::{Result, WorkspaceError};
5use crate::types::PackageInfo;
6use std::path::Path;
7
8#[derive(Debug, Clone, Copy)]
10pub enum PackageAdapter {
11 Cargo,
12}
13
14impl PackageAdapter {
15 pub fn all() -> &'static [PackageAdapter] {
18 &[PackageAdapter::Cargo]
19 }
20
21 pub fn can_discover(&self, root: &Path) -> bool {
23 match self {
24 Self::Cargo => cargo::CargoAdapter.can_discover(root),
25 }
26 }
27
28 pub fn discover(&self, root: &Path) -> std::result::Result<Vec<PackageInfo>, WorkspaceError> {
30 match self {
31 Self::Cargo => cargo::CargoAdapter.discover(root),
32 }
33 }
34
35 pub fn manifest_path(&self, package_dir: &Path) -> std::path::PathBuf {
37 match self {
38 Self::Cargo => cargo::CargoAdapter.manifest_path(package_dir),
39 }
40 }
41
42 pub fn is_publishable(&self, manifest_path: &Path) -> Result<bool> {
44 match self {
45 Self::Cargo => cargo::CargoAdapter.is_publishable(manifest_path),
46 }
47 }
48
49 pub fn version_exists(&self, package_name: &str, version: &str) -> Result<bool> {
51 match self {
52 Self::Cargo => cargo::CargoAdapter.version_exists(package_name, version),
53 }
54 }
55
56 pub fn publish(
58 &self,
59 manifest_path: &Path,
60 dry_run: bool,
61 extra_args: &[String],
62 ) -> Result<()> {
63 match self {
64 Self::Cargo => cargo::CargoAdapter.publish(manifest_path, dry_run, extra_args),
65 }
66 }
67
68 pub fn regenerate_lockfile(&self, workspace_root: &Path) -> Result<()> {
70 match self {
71 Self::Cargo => cargo::CargoAdapter.regenerate_lockfile(workspace_root),
72 }
73 }
74}