1mod ids;
2pub mod init;
3pub mod new;
4pub mod templates;
5
6pub use init::{
7 InitAction, InitGeneratedValues, RunxInitOptions, RunxInitResult, RunxInstallState,
8 RunxProjectState, ensure_runx_install_state, ensure_runx_project_state, runx_init,
9};
10pub use new::{RunxNewOptions, RunxNewResult, sanitize_runx_package_name, scaffold_runx_package};
11
12use std::fmt;
13use std::io;
14use std::path::PathBuf;
15
16#[derive(Debug)]
17pub enum ScaffoldError {
18 Io {
19 action: &'static str,
20 path: PathBuf,
21 source: io::Error,
22 },
23 Json {
24 action: &'static str,
25 path: PathBuf,
26 source: serde_json::Error,
27 },
28 InvalidState {
29 path: PathBuf,
30 message: String,
31 },
32 NonEmptyTarget {
33 path: PathBuf,
34 },
35}
36
37impl ScaffoldError {
38 pub(crate) fn io(action: &'static str, path: impl Into<PathBuf>, source: io::Error) -> Self {
39 Self::Io {
40 action,
41 path: path.into(),
42 source,
43 }
44 }
45
46 pub(crate) fn json(
47 action: &'static str,
48 path: impl Into<PathBuf>,
49 source: serde_json::Error,
50 ) -> Self {
51 Self::Json {
52 action,
53 path: path.into(),
54 source,
55 }
56 }
57}
58
59impl fmt::Display for ScaffoldError {
60 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
61 match self {
62 Self::Io {
63 action,
64 path,
65 source,
66 } => write!(formatter, "{action} {}: {source}", path.display()),
67 Self::Json {
68 action,
69 path,
70 source,
71 } => write!(formatter, "{action} {}: {source}", path.display()),
72 Self::InvalidState { path, message } => {
73 write!(
74 formatter,
75 "{} is not a valid Runx state: {message}",
76 path.display()
77 )
78 }
79 Self::NonEmptyTarget { path } => {
80 write!(
81 formatter,
82 "Refusing to scaffold into non-empty directory: {}",
83 path.display()
84 )
85 }
86 }
87 }
88}
89
90impl std::error::Error for ScaffoldError {}