Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hlafaille committed Sep 16, 2024
1 parent 92f6279 commit ec59317
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 52 deletions.
41 changes: 0 additions & 41 deletions dependency/command.go

This file was deleted.

1 change: 0 additions & 1 deletion dependency/resolver.go

This file was deleted.

26 changes: 26 additions & 0 deletions internal/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package internal

import (
"os/exec"
)

// CompileSourceFile compiles the sourcefile with the given project toolchain
func CompileSourceFile(cfg *ProjectConfig, srcFile *SourceFile) error {
// run the compiler
command := cfg.Toolchain.Path + "/bin/javac"
args := []string{}
if IsDebugMode() {
args = append(args, "-d", "ESPRESSO_DEBUG/build")
} else {
args = append(args, "build")
}
args = append(args, srcFile.Path)
cmd := exec.Command(command, args...)

// handle output
_, err := cmd.Output()
if err != nil {
return err
}
return nil
}
51 changes: 49 additions & 2 deletions project/command.go → internal/command.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package internal

import (
"fmt"
Expand All @@ -8,7 +8,7 @@ import (
"hlafaille.xyz/espresso/v0/toolchain"
)

func AssembleCommandHierarchy() *cobra.Command {
func GetProjectCommand() *cobra.Command {
var root = &cobra.Command{
Use: "project",
Short: "Manage a project within the current directory.",
Expand All @@ -31,6 +31,15 @@ func AssembleCommandHierarchy() *cobra.Command {
fmt.Printf("An error occurred while discovering source files: %s\n", err)
}
fmt.Printf("Discovered %d source file(s)\n", len(files))

// run the compiler on each source file
for _, value := range files {
println("Compiling: " + value.Path)
CompileSourceFile(cfg, &value)
}

// package the project
println("Done")
},
}
root.AddCommand(build)
Expand Down Expand Up @@ -97,3 +106,41 @@ func AssembleCommandHierarchy() *cobra.Command {

return root
}

func GetDependencyCommand() *cobra.Command {
var root = &cobra.Command{
Use: "dependency",
Short: "Manage dependencies for the project within the current directory.",
}

var query = &cobra.Command{
Use: "query",
Short: "Query the registries for the given search term.",
Aliases: []string{"q"},
Run: func(cmd *cobra.Command, args []string) {
println("TODO")
},
}
query.Flags().StringP("term", "t", "", "Term to query by")
query.MarkFlagRequired("term")
root.AddCommand(query)

var sync = &cobra.Command{
Use: "sync",
Short: "Sync dependencies declared in the project configuration with dependencies on the local filesystem.",
Run: func(cmd *cobra.Command, args []string) {
println("TODO")
},
}
root.AddCommand(sync)

var add = &cobra.Command{
Use: "add",
Short: "Add a dependency to the project configuration.",
Run: func(cmd *cobra.Command, args []string) {
println("TODO")
},
}
root.AddCommand(add)
return root
}
2 changes: 1 addition & 1 deletion project/handler.go → internal/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package internal

import (
"os"
Expand Down
1 change: 1 addition & 0 deletions internal/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package internal
2 changes: 1 addition & 1 deletion project/fs.go → internal/fs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package internal

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion project/discover.go → internal/source_discovery.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package internal

import (
"io/fs"
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package main

import (
"github.com/spf13/cobra"
"hlafaille.xyz/espresso/v0/dependency"
"hlafaille.xyz/espresso/v0/project"
"hlafaille.xyz/espresso/v0/internal"
)

func main() {
Expand All @@ -13,8 +12,8 @@ func main() {
}

// project commands
root.AddCommand(project.AssembleCommandHierarchy())
root.AddCommand(dependency.AssembleCommandHierarchy())
root.AddCommand(internal.GetProjectCommand())
root.AddCommand(internal.GetDependencyCommand())

// execute
root.Execute()
Expand Down
1 change: 0 additions & 1 deletion project/build.go

This file was deleted.

0 comments on commit ec59317

Please sign in to comment.