1use structopt::StructOpt;
2use crate::{run_new, run_dev};
3
4#[derive(StructOpt, Debug, PartialEq)]
5#[structopt(name="xylo", about="Self-hosted app creation kit")]
6pub enum Cli {
7 New {
8 project_name: String,
9 },
10 Dev,
11}
12
13pub trait ProjectHandler {
14 fn handle(&self, cli: &Cli);
15 fn handle_new(&self, project_name: &String);
16 fn handle_dev(&self);
17}
18pub struct DefaultProjectHandler;
19impl ProjectHandler for DefaultProjectHandler {
20 fn handle(&self, cli: &Cli) {
21 match cli {
22 Cli::New { project_name } => self.handle_new(project_name),
23 Cli::Dev => self.handle_dev(),
24 }
25 }
26 fn handle_new(&self, project_name: &String) {
27 run_new(project_name);
28 }
29 fn handle_dev(&self) {
30 run_dev();
31 }
32}
33
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_parse_new() {
41 let cli = Cli::from_iter(&["xylo", "new", "myproject"]);
42 assert_eq!(cli, Cli::New { project_name: "myproject".into() });
43 }
44}