use std::path::PathBuf;
use std::str::FromStr;
use clap::Parser;
use eyre::Result;
use serde::{Deserialize, Serialize};
use tap::Pipe as _;
use crate::output_path::OutputPath;
#[derive(Deserialize, Debug)]
pub struct Config {
#[serde(skip)]
pub root: PathBuf,
#[serde(rename = "link", default)]
pub links: Vec<Link>,
#[serde(rename = "dir", default)]
pub dirs: Vec<Dir>,
}
pub const GITHUB: &str = "https://github.com/nik-rev/dots";
impl Config {
pub const FILE_NAME: &str = "dots.toml";
}
#[derive(Parser)]
pub struct Marker {
#[arg(long)]
pub path: Option<OutputPath>,
}
impl Marker {
pub const MARKER: &str = "@dots ";
}
impl FromStr for Marker {
type Err = eyre::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
shellwords::split(s)?.pipe(Marker::try_parse_from)?.pipe(Ok)
}
}
#[derive(Deserialize, Debug)]
pub struct Dir {
pub input: PathBuf,
pub output: OutputPath,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Link {
pub url: String,
pub path: PathBuf,
pub sha256: Option<String>,
pub marker: Option<String>,
}