diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index 84124d41..4bd37897 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "os" "path/filepath" "strings" @@ -39,6 +40,20 @@ func newCliApp( //nolint:funlen return nil }, }, + { + Name: "new", + Usage: "Get current Nevalang version", + Args: true, + Action: func(cCtx *cli.Context) error { + if path := cCtx.Args().First(); path != "" { + if err := os.Mkdir(path, 0755); err != nil { + return err + } + return createNevaMod(path) + } + return createNevaMod(workdir) + }, + }, { Name: "get", Usage: "Add dependency to current module", @@ -144,3 +159,42 @@ func getMainPkgFromArgs(cCtx *cli.Context) (string, error) { } return dirFromArg, nil } + +func createNevaMod(path string) error { + // Create neva.yml file + nevaYmlContent := fmt.Sprintf("neva: %s", pkg.Version) + if err := os.WriteFile( + filepath.Join(path, "neva.yml"), + []byte(nevaYmlContent), + 0644, + ); err != nil { + return err + } + + // Create src sub-directory + srcPath := filepath.Join(path, "src") + if err := os.Mkdir(srcPath, 0755); err != nil { + return err + } + + // Create main.neva file + mainNevaContent := `component Main(start any) (stop any) { + nodes { + + } + net { + :start -> :stop + } +} +` + + if err := os.WriteFile( + filepath.Join(srcPath, "main.neva"), + []byte(mainNevaContent), + 0644, + ); err != nil { + return err + } + + return nil +} diff --git a/examples/2_hello_world/0_verbose/main.neva b/examples/2_hello_world/0_verbose/main.neva index 5b761c20..387dc5c2 100644 --- a/examples/2_hello_world/0_verbose/main.neva +++ b/examples/2_hello_world/0_verbose/main.neva @@ -1,6 +1,3 @@ -// Surprisingly "hello world" isn't the simplest program in Nevalang. -// Here we learn constants, compiler directives and blockers. - const greeting string = 'Hello, World!' component Main(start any) (stop any) { diff --git a/examples/2_hello_world/1_with_const_sender/main.neva b/examples/2_hello_world/1_with_const_sender/main.neva index 8688f11f..a07f9275 100644 --- a/examples/2_hello_world/1_with_const_sender/main.neva +++ b/examples/2_hello_world/1_with_const_sender/main.neva @@ -1,6 +1,3 @@ -// In this example we use `$` suntatic sugar called "const sender" -// that allows to avoid using compiler directives for sending constants. - const greeting string = 'Hello, World!' component Main(start any) (stop any) { diff --git a/examples/2_hello_world/2_with_then_connection/main.neva b/examples/2_hello_world/2_with_then_connection/main.neva index 73d20d92..45975171 100644 --- a/examples/2_hello_world/2_with_then_connection/main.neva +++ b/examples/2_hello_world/2_with_then_connection/main.neva @@ -1,7 +1,3 @@ -// Now it's time to learn another syntatic sugar `... -> (...)` -// Called "then connections" that allows to avoid explicit usage of blockers. -// It's extremely useful when working with constants to keep code simple. - const greeting string = 'Hello, World!' component Main(start any) (stop any) { diff --git a/examples/2_hello_world/3_with_literal_sender/main.neva b/examples/2_hello_world/3_with_literal_sender/main.neva index b07813b5..061874af 100644 --- a/examples/2_hello_world/3_with_literal_sender/main.neva +++ b/examples/2_hello_world/3_with_literal_sender/main.neva @@ -1,10 +1,3 @@ -// Finally, the shortest "hello world" with "literal senders". -// Why have const senders then, one might ask? -// First of all, only primitive messages such as bool, int, float and string -// could be used as network senders. So no structs, lists or maps senders. -// Secondly, what if you wanna use your message in several places? -// Finally, you might wanna move your message to const just because it's big! - component Main(start any) (stop any) { nodes { printer Printer } net { diff --git a/examples/2_hello_world/4_with_unnamed_node/main.neva b/examples/2_hello_world/4_with_unnamed_node/main.neva index 4f7f3c6e..51142f1f 100644 --- a/examples/2_hello_world/4_with_unnamed_node/main.neva +++ b/examples/2_hello_world/4_with_unnamed_node/main.neva @@ -1,10 +1,3 @@ -// Finally, the shortest "hello world" with "literal senders". -// Why have const senders then, one might ask? -// First of all, only primitive messages such as bool, int, float and string -// could be used as network senders. So no structs, lists or maps senders. -// Secondly, what if you wanna use your message in several places? -// Finally, you might wanna move your message to const just because it's big! - component Main(start any) (stop any) { nodes { Printer } net { diff --git a/examples/5_add_real_numbers/with_err_handling/main.neva b/examples/5_add_real_numbers/with_err_handling/main.neva index c2464960..3a392129 100644 --- a/examples/5_add_real_numbers/with_err_handling/main.neva +++ b/examples/5_add_real_numbers/with_err_handling/main.neva @@ -1,8 +1,4 @@ -// Here we learn how to handle errors by fixing this simple program - -import { - x -} +import { x } component Main(start any) (stop any) { nodes { diff --git a/examples/5_add_real_numbers/with_sub_components/main.neva b/examples/5_add_real_numbers/with_sub_components/main.neva index 6078ea58..4d334622 100644 --- a/examples/5_add_real_numbers/with_sub_components/main.neva +++ b/examples/5_add_real_numbers/with_sub_components/main.neva @@ -1,5 +1,3 @@ -// Here we learn how to simplify program by separating concerns - import { x } component { diff --git a/examples/6_struct_builder/with_sugar/main.neva b/examples/6_struct_builder/with_sugar/main.neva index 44fd869f..18e9664c 100644 --- a/examples/6_struct_builder/with_sugar/main.neva +++ b/examples/6_struct_builder/with_sugar/main.neva @@ -1,7 +1,3 @@ -// Here we learn how to build structures -// without custom component and compiler directives -// by simply using builtin StructBuilder. - type User struct { age int name string diff --git a/pkg/version.go b/pkg/version.go index 81df1ae6..a99f9ce9 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -1,4 +1,4 @@ package pkg // Version is the current version of the language and stdlib -var Version = "0.7.0" //nolint:gochecknoglobals +var Version = "0.8.0" //nolint:gochecknoglobals