Skip to content

Commit

Permalink
update config and files
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-the-programmer committed Jul 28, 2022
1 parent 0793403 commit b0838c0
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "Build",
"type": "shell",
"command": ".\\build.bat",
"command": ".\\run.bat",
"problemMatcher": [],
"group": {
"kind": "build",
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

# 🏰 <br> Sandcastle

Sandcastle is a blazingly fast, lightweight build tool for any language or shell.
Sandcastle is a blazingly fast, lightweight build tool for any language or shell. With a simple call to the `castle` command, you can build and run your project in seconds.

</section>

## Installation
Download the latest release from our [GitHub Release](https://github.com/neuron-ai/sandcastle/releases/latest), and add it to your PATH environment variable. You may have to rename the file to **castle**, if you are on *MacOS*, as the file is called **castle-macos**

## Usage

To build and run, simply use...

```bash
castle castle.yaml
castle
```

Where castle.yaml is similar to...
Expand All @@ -26,3 +28,14 @@ run:
- run_section arg1
- run_more_sections arg1
```
## CLI Arguments
```bash
Usage of castle.exe:
-b, -build Build the project.
-c, -config Config YAML file to parse. (default "castle.yml")
-r, -run Run the project.
-v, -version Show version.
```
16 changes: 12 additions & 4 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
@echo off
go build main.go
move main.exe ./bin/castle.exe
cls
.\bin\castle.exe test/castle.yaml

set GOOS=windows
go build -o=bin/castle.exe main.go
echo "Built for windows."

set GOOS=linux
go build -o=bin/castle main.go
echo "Built for linux."

set GOOS=darwin
go build -o=bin/castle-macos main.go
echo "Built for mac."
39 changes: 37 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"castle/parse"
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -14,12 +15,46 @@ const (
LIGHTCYAN = "\033[1;36m"
LIGHTPURPLE = "\033[1;35m"
RESET = "\033[0m"

VERSION = "v0.0.1"
)

var (
filename = flag.String("config", "castle.yaml", "Config YAML file to parse.")
showVersion = flag.Bool("version", false, "Show version and exit.")
shouldBuild = flag.Bool("build", false, "Build the project.")
shouldRun = flag.Bool("run", false, "Run the project.")
)

func init() {
flag.StringVar(filename, "c", "castle.yml", "Config YAML file to parse.")
flag.BoolVar(showVersion, "v", false, "Show version.")
flag.BoolVar(shouldBuild, "b", false, "Build the project.")
flag.BoolVar(shouldRun, "r", false, "Run the projecte.")
}

func main() {
fmt.Println(LIGHTPURPLE, "\bCastle v0.0.1\n", RESET)
flag.Parse()

config := parse.Parse(os.Args[1])
if *showVersion {
fmt.Println(LIGHTPURPLE, "\bCastle", VERSION, RESET)
os.Exit(0)
}

fmt.Println(LIGHTPURPLE, "\bCastle", VERSION, RESET)
config := parse.Parse(*filename)

if *shouldBuild {
fmt.Println("Building...")
RunSection(config.Build)
os.Exit(0)
}

if *shouldRun {
fmt.Println("Running...")
RunSection(config.Run)
os.Exit(0)
}

fmt.Println(LIGHTBLUE, "\bBuilding... 🔨", RESET)
RunSection(config.Build)
Expand Down
11 changes: 8 additions & 3 deletions parse/parser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package parse

import (
"log"
"fmt"
"os"

"gopkg.in/yaml.v3"
Expand All @@ -13,16 +13,21 @@ type T struct {
}

func Parse(filename string) T {
fmt.Println("File → ", filename)
fmt.Println()

t := T{}

// Read the file
f, err := os.ReadFile(filename)
if err != nil {
log.Fatal(err)
fmt.Println(err)
os.Exit(1)
}

if err := yaml.Unmarshal(f, &t); err != nil {
log.Fatal(err)
fmt.Println(err)
os.Exit(1)
}

return t
Expand Down
4 changes: 4 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
go build -o=./bin/castle.exe main.go
cls
.\bin\castle.exe -h
4 changes: 2 additions & 2 deletions test/castle.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
- test/tools/file.exe build
- ./file.exe build

run:
- test/tools/file.exe run
- ./file.exe run
2 changes: 1 addition & 1 deletion test/tools/src/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
if os.Args[1] == "build" {
fmt.Println("Built 🧱")
} else if os.Args[1] == "run" {
fmt.Println("Running, running, running, running... 🏃‍♀️💨")
fmt.Println("Running, running, running, running... 🏃💨")
} else {
fmt.Println(os.Args[1])
}
Expand Down

0 comments on commit b0838c0

Please sign in to comment.