oceanpkg/drop/kind/
exe.rs

1use std::{
2    path::PathBuf,
3    process::Command,
4};
5use crate::{
6    drop::{
7        Metadata,
8        name::Query,
9    },
10    install::InstallTarget,
11};
12
13/// A package that can be executed; e.g. CLI tool or script.
14#[derive(Clone, Debug)]
15pub struct Exe {
16    metadata: Metadata,
17    bin_name: String,
18}
19
20impl Exe {
21    /// Returns an executable matching `query`, installed for `target`.
22    pub fn installed<S: AsRef<str>>(
23        query: &Query<S>,
24        target: &InstallTarget,
25    ) -> Result<Self, ()> {
26        let query = query.to_ref::<str>();
27        unimplemented!("TODO: Find installation of {:?} for {:?}", query, target)
28    }
29
30    /// Returns basic metadata for the drop.
31    #[inline]
32    pub const fn metadata(&self) -> &Metadata {
33        &self.metadata
34    }
35
36    /// Returns the name of the binary executable.
37    #[inline]
38    pub fn bin_name(&self) -> &str {
39        &self.bin_name
40    }
41
42    /// Returns the path of the drop's executable binary, if one exists.
43    pub fn bin_path<'t>(
44        &self,
45        target: &'t InstallTarget,
46    ) -> Result<PathBuf, FindError<'t>> {
47        unimplemented!(
48            "TODO: Find {:?} binary for {:?}",
49            self.metadata.name,
50            target,
51        )
52    }
53
54    /// Returns a `Command` instance suitable for running the drop's executable
55    /// binary, if one exists.
56    pub fn command<'t>(
57        &self,
58        target: &'t InstallTarget
59    ) -> Result<Command, FindError<'t>> {
60        self.bin_path(target).map(Command::new)
61    }
62}
63
64/// An error returned when the binary for an executable drop cannot be found.
65#[derive(Debug)]
66pub struct FindError<'a> {
67    target: &'a InstallTarget,
68}