Skip to main content

distrib_ruby/
program.rs

1// This is free and unencumbered software released into the public domain.
2
3use alloc::{boxed::Box, string::String, vec::Vec};
4use core::error::Error;
5use distrib_common::{BoxError, Build, Clean, PackageRegistry, Publish, Tool, Utf8PathBuf};
6use std::process::Command;
7
8pub const GEM_COMMAND: &str = "gem";
9
10#[derive(Clone, Debug, Eq, Hash, PartialEq)]
11pub struct GemProgram(Utf8PathBuf);
12
13impl Default for GemProgram {
14    fn default() -> Self {
15        Self(GEM_COMMAND.into())
16    }
17}
18
19impl From<Utf8PathBuf> for GemProgram {
20    fn from(input: Utf8PathBuf) -> Self {
21        Self(input)
22    }
23}
24
25impl<T> From<&T> for GemProgram
26where
27    T: Clone + Into<Self>,
28{
29    fn from(t: &T) -> Self {
30        t.clone().into()
31    }
32}
33
34impl From<GemProgram> for Command {
35    fn from(input: GemProgram) -> Self {
36        Command::new(input.0)
37    }
38}
39
40impl GemProgram {}
41
42impl Tool for GemProgram {}
43
44impl Clean for GemProgram {
45    fn clean(&self) -> Result<(), BoxError> {
46        Ok(())
47    }
48}
49
50impl Build for GemProgram {
51    fn build(&self) -> Result<(), BoxError> {
52        let mut cmd = Command::from(self.clone());
53        cmd.args(["build"]);
54
55        #[cfg(feature = "tracing")]
56        tracing::info!("Executing {:?}", cmd);
57
58        cmd.status().map_err(|err| Box::new(err))?;
59        Ok(())
60    }
61}
62
63impl Publish for GemProgram {
64    fn publish(&self, _registry: Option<PackageRegistry>) -> Result<(), BoxError> {
65        todo!() // TODO
66    }
67}