Skip to content

Commit

Permalink
feat: migrate back from cmd to git root main
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Voltaire authored and viktorvoltaire committed Jan 27, 2022
1 parent 7369fbe commit 0d1fdf7
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
sagefile := .sage/tools/bin/sagefile

$(sagefile): .sage/go.mod $(shell find .sage/.. -type f -name '*.go')
@cd .sage && go run ../cmd/build
@cd .sage && go run ../main.go run

.PHONY: clean-sage
clean-sage:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Getting started
To initilize Sage in a repository, just run:

```bash
go run go.einride.tech/sage/cmd/init@latest
go run go.einride.tech/sage@latest init
```

Run `make`.
Expand Down
23 changes: 0 additions & 23 deletions cmd/build/main.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions cmd/init/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ var (

func main() {
ctx := logr.NewContext(context.Background(), sg.NewLogger("sage"))
logger := logr.FromContextOrDiscard(ctx)
usage := func() {
logger.Info(`Usage:
init
to initialize sage
run
to run sage`)
os.Exit(0)
}
if len(os.Args) < 2 || len(os.Args) > 2 {
usage()
}
switch os.Args[1] {
case "init":
initSage(ctx)
case "run":
runSage(ctx)
default:
usage()
}
}

func runSage(ctx context.Context) {
cmd := sg.Command(ctx, "go", "mod", "tidy")
cmd.Dir = sg.FromSageDir()
if err := cmd.Run(); err != nil {
panic(err)
}
cmd = sg.Command(ctx, "go", "run", ".")
cmd.Dir = sg.FromSageDir()
if err := cmd.Run(); err != nil {
panic(err)
}
}

func initSage(ctx context.Context) {
logger := logr.FromContextOrDiscard(ctx)
logger.Info("initializing sage...")
if sg.FromWorkDir() != sg.FromGitRoot() {
Expand Down
4 changes: 2 additions & 2 deletions sg/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func generateMakefile(g *codegen.File, pkg *doc.Package, mk Makefile, mks ...Mak
return err
}
dependencies := fmt.Sprintf("%s/go.mod %s/*.go", includePath, includePath)
genCommand := fmt.Sprintf("cd %s && go run go.einride.tech/sage/cmd/build", includePath)
genCommand := fmt.Sprintf("cd %s && go run go.einride.tech/sage run", includePath)
if strings.TrimSpace(b.String()) == "go.einride.tech/sage" {
dependencies = fmt.Sprintf("%s/go.mod $(shell find %s/.. -type f -name '*.go')", includePath, includePath)
genCommand = fmt.Sprintf("cd %s && go run ../cmd/build", includePath)
genCommand = fmt.Sprintf("cd %s && go run ../main.go run", includePath)
}

g.P("# To learn more, see ", includePath, "/sagefile.go and https://github.com/einride/sage.")
Expand Down

0 comments on commit 0d1fdf7

Please sign in to comment.