Skip to main content

bleur/
lib.rs

1pub mod error;
2pub mod execute;
3pub mod manager;
4pub mod method;
5pub mod schemes;
6
7use crate::method::Methodical;
8use clap::{Parser, Subcommand, ValueEnum};
9pub use error::{BleurError as Error, Result, beautiful_exit};
10use method::{Method, git::Git, http::Http};
11use std::path::PathBuf;
12use url::Url;
13
14pub static TEMPLATE: &str = include_str!("./template/template.toml");
15pub static COLLECTION: &str = include_str!("./template/collection.toml");
16
17#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
18pub enum Protocol {
19    Git,
20    Http,
21}
22
23impl std::fmt::Display for Protocol {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            Self::Git => write!(f, "git"),
27            Self::Http => write!(f, "http"),
28        }
29    }
30}
31
32impl Methodical for Protocol {
33    fn to_method(&self, url: Url, path: PathBuf) -> method::Method {
34        match self {
35            Self::Git => Method::Git(Git::new(url, path)),
36            Self::Http => Method::Http(Http::new(url, path)),
37        }
38    }
39}
40
41/// That buddy that will get everything ready for you
42#[derive(Debug, Parser)]
43#[command(name = "bleur", version)]
44#[command(
45    about = "That buddy that will get everything ready for you",
46    long_about = "A template assistant from Bleur to manage your templates, bootstrap your project quickly!"
47)]
48pub struct Cli {
49    #[command(subcommand)]
50    pub command: Commands,
51}
52
53#[derive(Debug, Subcommand)]
54pub enum Commands {
55    /// Start creating new project
56    New {
57        /// Path where template should be
58        /// bootstrapped to [default: current working directory]
59        #[arg(value_name = "WHERE")]
60        path: Option<PathBuf>,
61
62        /// URL to a repository or nix flake
63        /// of template or collection fo templates
64        #[arg(short, long)]
65        #[clap(default_value = "https://git.oss.uzinfocom.uz/bleur/templates.git")]
66        template: String,
67
68        /// Chosen method of fetching repository
69        #[arg(short, long)]
70        #[clap(default_value_t = Protocol::Git)]
71        method: Protocol,
72    },
73
74    /// Bootstrap a bleur toml file for a new template
75    Init,
76}