Skip to content

Commit

Permalink
Merge pull request #482 from nevalang/newcmd
Browse files Browse the repository at this point in the history
New cmd
  • Loading branch information
emil14 authored Mar 2, 2024
2 parents f90cd3b + 8267512 commit 099f9c1
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 36 deletions.
54 changes: 54 additions & 0 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
3 changes: 0 additions & 3 deletions examples/2_hello_world/0_verbose/main.neva
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions examples/2_hello_world/1_with_const_sender/main.neva
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions examples/2_hello_world/2_with_then_connection/main.neva
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
7 changes: 0 additions & 7 deletions examples/2_hello_world/3_with_literal_sender/main.neva
Original file line number Diff line number Diff line change
@@ -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<string> }
net {
Expand Down
7 changes: 0 additions & 7 deletions examples/2_hello_world/4_with_unnamed_node/main.neva
Original file line number Diff line number Diff line change
@@ -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<string> }
net {
Expand Down
6 changes: 1 addition & 5 deletions examples/5_add_real_numbers/with_err_handling/main.neva
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions examples/5_add_real_numbers/with_sub_components/main.neva
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Here we learn how to simplify program by separating concerns

import { x }

component {
Expand Down
4 changes: 0 additions & 4 deletions examples/6_struct_builder/with_sugar/main.neva
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 099f9c1

Please sign in to comment.