From d7a3f1996773f1465acbe0c7f83b9c6eafd1cbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:30:56 +0200 Subject: [PATCH] Add default main.shu file to init command --- assets/default-main.shu | 5 +++++ src/subcommands/init.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 assets/default-main.shu diff --git a/assets/default-main.shu b/assets/default-main.shu new file mode 100644 index 0000000..58b70b9 --- /dev/null +++ b/assets/default-main.shu @@ -0,0 +1,5 @@ +#[tick] +fn main() { + // Change this + /say Hello World! +} \ No newline at end of file diff --git a/src/subcommands/init.rs b/src/subcommands/init.rs index 752472f..b3f1f19 100644 --- a/src/subcommands/init.rs +++ b/src/subcommands/init.rs @@ -40,6 +40,9 @@ pub fn init( let src_path = path.join("src"); create_dir(&src_path, verbose)?; + // Create the main.shu file + create_main_file(path, verbose)?; + print_success("Project initialized successfully."); Ok(()) @@ -116,3 +119,15 @@ fn create_pack_png(path: &Path, verbose: bool) -> std::io::Result<()> { } Ok(()) } + +fn create_main_file(path: &Path, verbose: bool) -> std::io::Result<()> { + let main_file = path.join("src").join("main.shu"); + fs::write(&main_file, include_str!("../../assets/default-main.shu"))?; + if verbose { + print_info(&format!( + "Created main.shu file at {}.", + to_absolute_path(&main_file)? + )); + } + Ok(()) +}