diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-08-20 01:37:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-20 01:37:05 +0200 |
commit | 1ffbd561642d05a05e18ada764d50581dea779ef (patch) | |
tree | 93bc8b6c613b8f76c2b5ca713975bca44df4ad61 /cli/main.rs | |
parent | 5beec3f106b0890cc76150d0e3b3661c576d4c3b (diff) |
feat: add "deno init" subcommand (#15469)
This adds an init subcommand to that creates a project starter similar to cargo init.
```
$ deno init my_project
Project initialized
Run these commands to get started:
cd my_project
deno run main.ts
deno run main_test.ts
$ deno run main.ts
Add 2 + 3 5
$ cat main.ts
export function add(a: number, b: number): number {
return a + b;
}
if (import.meta.main) {
console.log("Add 2 + 3", add(2, 3));
}
$ cat main_test.ts
import { assertEquals } from "https://deno.land/std@0.151.0/testing/asserts.ts";
import { add } from "./main.ts";
Deno.test(function addTest() {
assertEquals(add(2, 3), 5);
});
```
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/cli/main.rs b/cli/main.rs index b157b3582..db625e404 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -51,6 +51,7 @@ use crate::args::EvalFlags; use crate::args::Flags; use crate::args::FmtFlags; use crate::args::InfoFlags; +use crate::args::InitFlags; use crate::args::InstallFlags; use crate::args::LintFlags; use crate::args::ReplFlags; @@ -273,6 +274,14 @@ async fn compile_command( Ok(0) } +async fn init_command( + _flags: Flags, + init_flags: InitFlags, +) -> Result<i32, AnyError> { + tools::init::init_project(init_flags).await?; + Ok(0) +} + async fn info_command( flags: Flags, info_flags: InfoFlags, @@ -941,6 +950,9 @@ fn get_subcommand( DenoSubcommand::Fmt(fmt_flags) => { format_command(flags, fmt_flags).boxed_local() } + DenoSubcommand::Init(init_flags) => { + init_command(flags, init_flags).boxed_local() + } DenoSubcommand::Info(info_flags) => { info_command(flags, info_flags).boxed_local() } |