use camino::Utf8PathBuf;
use std::fmt;
macro_rules! string_newtype {
($name:ident, $doc:literal) => {
#[doc = $doc]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct $name(String);
impl $name {
#[must_use]
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
#[must_use]
pub fn into_inner(self) -> String {
self.0
}
}
impl From<String> for $name {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<&str> for $name {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
impl AsRef<str> for $name {
fn as_ref(&self) -> &str {
&self.0
}
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
};
}
string_newtype!(ModuleName, "PowerShell module name.");
string_newtype!(ModuleVersion, "PowerShell module version.");
string_newtype!(BinaryName, "Executable name exposed by the wrapper.");
string_newtype!(ExportAlias, "Alias exported by the wrapper module.");
string_newtype!(
HelpInfoUri,
"URI used by `Update-Help` for payload discovery."
);
#[derive(Debug, Clone)]
pub struct PowerShellConfig {
pub out_dir: Utf8PathBuf,
pub module_name: ModuleName,
pub module_version: ModuleVersion,
pub bin_name: BinaryName,
pub export_aliases: Vec<ExportAlias>,
pub should_include_common_parameters: bool,
pub should_split_subcommands: bool,
pub help_info_uri: Option<HelpInfoUri>,
pub should_ensure_en_us: bool,
}
impl PowerShellConfig {
#[must_use]
pub fn module_root(&self) -> Utf8PathBuf {
self.out_dir
.join("powershell")
.join(self.module_name.as_ref())
}
}
#[derive(Debug, Default, Clone)]
pub struct PowerShellOutput {
pub files: Vec<Utf8PathBuf>,
}
impl PowerShellOutput {
#[must_use]
pub const fn new() -> Self {
Self { files: Vec::new() }
}
pub fn add_file(&mut self, path: Utf8PathBuf) {
self.files.push(path);
}
pub fn extend<I>(&mut self, paths: I)
where
I: IntoIterator<Item = Utf8PathBuf>,
{
self.files.extend(paths);
}
}