Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
DobromirM committed Sep 11, 2023
1 parent 983c190 commit c0c4043
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/file_names.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const FOLDER_CREATE_ERROR: &str = "Unable to create folder!";
pub const FILE_WRITE_ERROR: &str = "Unable to write file!";
38 changes: 20 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
mod file_names;

use std::fs;
use clap::Parser;
use boilerplate;
use boilerplate::Boilerplate;
use crate::file_names::{FILE_WRITE_ERROR, FOLDER_CREATE_ERROR};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Name of the project
/// The name of the project
name: String,
/// Port of the Swim application
/// The port of the Swim application
#[arg(long, default_value_t = 9001)]
port: u16,
/// Version of the Swim application
/// The version of the Swim server dependencies
#[arg(long, default_value = "4.0.1")]
swim_version: String,
}
Expand Down Expand Up @@ -56,9 +58,8 @@ struct Gradlew;
#[boilerplate(filename = "gradlew.bat")]
struct GradlewBat;


#[derive(Boilerplate)]
#[boilerplate(filename = "test/.gitignore")]
#[boilerplate(filename = ".gitignore")]
struct Gitignore;

fn main() {
Expand All @@ -69,16 +70,17 @@ fn main() {
println!("Swim version: {}", args.swim_version);

fs::create_dir(&args.name).unwrap();
fs::create_dir_all(format!("{0}/src/main/java/{0}", args.name)).unwrap();
fs::create_dir_all(format!("{0}/src/main/resources", args.name)).unwrap();

fs::write(format!("{0}/{SETTINGS_GRADLE}", args.name), SettingsGradle { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/build.gradle", args.name), BuildGradle { name: &args.name, swim_version: &args.swim_version }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/.gitignore", args.name), Gitignore.to_string()).expect("Unable to write file");
fs::write(format!("{0}/gradlew", args.name), Gradlew.to_string()).expect("Unable to write file");
fs::write(format!("{0}/gradlew.bat", args.name), GradlewBat.to_string()).expect("Unable to write file");

fs::write(format!("{0}/src/main/java/{0}/MainPlane.java", args.name), MainPlaneJava { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/src/main/java/module-info.java", args.name), ModuleInfoJava { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/src/main/resources/server.recon", args.name), ServerRecon { name: &args.name, port: args.port }.to_string()).expect("Unable to write file");
fs::create_dir_all(format!("{0}/src/main/java/{0}", args.name)).expect(FOLDER_CREATE_ERROR);
fs::create_dir_all(format!("{0}/src/main/resources", args.name)).expect(FOLDER_CREATE_ERROR);

fs::write(format!("{0}/settings.gradle", args.name), SettingsGradle { name: &args.name }.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/build.gradle", args.name), BuildGradle { name: &args.name, swim_version: &args.swim_version }.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/.gitignore", args.name), Gitignore.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/gradlew", args.name), Gradlew.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/gradlew.bat", args.name), GradlewBat.to_string()).expect(FILE_WRITE_ERROR);

fs::write(format!("{0}/src/main/java/{0}/MainPlane.java", args.name), MainPlaneJava { name: &args.name }.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/src/main/java/module-info.java", args.name), ModuleInfoJava { name: &args.name }.to_string()).expect(FILE_WRITE_ERROR);
fs::write(format!("{0}/src/main/resources/server.recon", args.name), ServerRecon { name: &args.name, port: args.port }.to_string()).expect(FILE_WRITE_ERROR);
}

0 comments on commit c0c4043

Please sign in to comment.