-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathfrontend.rs
More file actions
124 lines (120 loc) · 3.77 KB
/
frontend.rs
File metadata and controls
124 lines (120 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pub mod build;
mod cli;
mod fmt;
mod new;
mod run;
use std::process::ExitCode;
use clap::{
CommandFactory,
Parser,
};
use cli::{
Cli,
Command,
};
use colored::Colorize;
use new::NewError;
use run::RunError;
use crate::{
config::Config,
fmt::FmtError,
interpreter::Exception,
};
pub fn frontend() -> ExitCode {
match Cli::parse().command {
Command::Build {
input,
output,
release,
} => match build::build(input, output, release) {
Ok(artifact) => {
artifact.eprint();
eprintln!();
if artifact.failure() {
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}
Err(err) => {
eprintln!("{}: {:?}", "error".red().bold(), err);
ExitCode::FAILURE
}
},
Command::Completions { shell } => {
shell.generate(&mut Cli::command(), &mut std::io::stdout());
ExitCode::SUCCESS
}
Command::New {
name,
std,
frame_rate,
max_clones,
no_miscellaneous_limits,
no_sprite_fencing,
frame_interpolation,
high_quality_pen,
stage_width,
stage_height,
} => {
match new::new(
name,
Config {
std,
frame_rate,
max_clones,
no_miscellaneous_limits: Some(no_miscellaneous_limits),
no_sprite_fencing: Some(no_sprite_fencing),
frame_interpolation: Some(frame_interpolation),
high_quality_pen: Some(high_quality_pen),
stage_width,
stage_height,
},
) {
Err(NewError::AnyhowError(err)) => {
eprintln!("{}: {:?}", "error".red().bold(), err);
ExitCode::FAILURE
}
Err(NewError::NewDirNotEmpty {
name,
is_name_explicit,
}) => {
eprintln!("{}: {} is not empty", "error".red().bold(), name.display());
if !is_name_explicit {
eprintln!("{}: use --name to specify a name", "hint".blue().bold());
}
ExitCode::FAILURE
}
Ok(_) => ExitCode::SUCCESS,
}
}
Command::Fmt { input } => match fmt::fmt(input) {
Ok(_) => ExitCode::SUCCESS,
Err(FmtError::AnyhowError(err)) => {
eprintln!("{}: {:?}", "error".red().bold(), err);
ExitCode::FAILURE
}
},
Command::Run { input } => match run::run(input) {
Ok(_) => ExitCode::SUCCESS,
Err(RunError::ProjectDiagnostics(diagnostics)) => {
diagnostics.eprint();
eprintln!();
if diagnostics.failure() {
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}
Err(RunError::AnyhowError(err)) => {
eprintln!("{}: {:?}", "error".red().bold(), err);
ExitCode::FAILURE
}
Err(RunError::Exception(Exception { message, span })) => {
eprintln!("{}: {:?}", "error".red().bold(), message);
eprintln!("{}: {:?}", "span".blue().bold(), span);
ExitCode::FAILURE
}
},
}
}