Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/cmd/uloop-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"os"

"github.com/hatayama/unity-cli-loop/cli/internal/cli"
"github.com/hatayama/unity-cli-loop/cli/internal/projectcli"
)

func main() {
os.Exit(cli.RunProjectLocal(context.Background(), os.Args[1:], os.Stdout, os.Stderr))
os.Exit(projectcli.Run(context.Background(), os.Args[1:], os.Stdout, os.Stderr))
}
4 changes: 2 additions & 2 deletions cli/cmd/uloop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"os"

"github.com/hatayama/unity-cli-loop/cli/internal/cli"
"github.com/hatayama/unity-cli-loop/cli/internal/dispatcher"
)

func main() {
os.Exit(cli.RunDispatcher(context.Background(), os.Args[1:], os.Stdout, os.Stderr))
os.Exit(dispatcher.Run(context.Background(), os.Args[1:], os.Stdout, os.Stderr))
}
2 changes: 1 addition & 1 deletion cli/dispatcher-contract.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schemaVersion": 1,
"dispatcherVersion": "3.0.1-beta.4",
"dispatcherVersion": "3.0.1-beta.5",
"dispatcherContractVersion": 1
}
27 changes: 20 additions & 7 deletions cli/internal/architecture/architecture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func TestCliFeaturePackagesDoNotImportCli(t *testing.T) {
moduleRoot := findModuleRoot(t)
packages := listPackages(t, moduleRoot)
for _, goPackage := range packages {
if goPackage.ImportPath == cliModulePath+"/internal/cli" || strings.HasPrefix(goPackage.ImportPath, cliModulePath+"/cmd/") {
if goPackage.ImportPath == cliModulePath+"/internal/cli" ||
goPackage.ImportPath == cliModulePath+"/internal/dispatcher" ||
goPackage.ImportPath == cliModulePath+"/internal/projectcli" ||
strings.HasPrefix(goPackage.ImportPath, cliModulePath+"/cmd/") {
continue
}
for _, importedPath := range goPackage.Imports {
Expand All @@ -68,7 +71,7 @@ func TestCliInternalPackagesStayInsideExplicitBoundaries(t *testing.T) {
if goPackage.ImportPath == cliModulePath+"/internal/architecture" {
continue
}
for _, boundary := range []string{"/internal/automation", "/internal/cli", "/internal/install", "/internal/project", "/internal/skills", "/internal/tools", "/internal/uninstall", "/internal/unityipc", "/internal/update", "/internal/version"} {
for _, boundary := range []string{"/internal/automation", "/internal/cli", "/internal/dispatcher", "/internal/install", "/internal/project", "/internal/projectcli", "/internal/skills", "/internal/tools", "/internal/uninstall", "/internal/unityipc", "/internal/update", "/internal/version"} {
if strings.Contains(goPackage.ImportPath, boundary) {
goto nextPackage
}
Expand All @@ -78,10 +81,20 @@ func TestCliInternalPackagesStayInsideExplicitBoundaries(t *testing.T) {
}
}

// Tests that the native CLI command only enters the CLI orchestration package.
func TestCliCommandOnlyDependsOnCliEntrypoint(t *testing.T) {
// Tests that the dispatcher command only enters the dispatcher package.
func TestDispatcherCommandOnlyDependsOnDispatcherEntrypoint(t *testing.T) {
assertCommandOnlyDependsOnInternalEntrypoint(t, "./cmd/uloop", cliModulePath+"/internal/dispatcher")
}

// Tests that the project-local CLI command only enters the project CLI package.
func TestProjectCliCommandOnlyDependsOnProjectCliEntrypoint(t *testing.T) {
assertCommandOnlyDependsOnInternalEntrypoint(t, "./cmd/uloop-cli", cliModulePath+"/internal/projectcli")
}

func assertCommandOnlyDependsOnInternalEntrypoint(t *testing.T, commandPath string, expectedEntrypoint string) {
t.Helper()
moduleRoot := findModuleRoot(t)
command := exec.Command("go", "list", "-json", "./cmd/uloop")
command := exec.Command("go", "list", "-json", commandPath)
command.Dir = moduleRoot
output, err := command.Output()
if err != nil {
Expand All @@ -101,8 +114,8 @@ func TestCliCommandOnlyDependsOnCliEntrypoint(t *testing.T) {
if !strings.HasPrefix(dependency, cliModulePath+"/internal/") {
continue
}
if dependency != cliModulePath+"/internal/cli" {
t.Fatalf("CLI command must enter internal code through internal/cli, got %s", dependency)
if dependency != expectedEntrypoint {
t.Fatalf("%s must enter internal code through %s, got %s", commandPath, expectedEntrypoint, dependency)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions cli/internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dispatcher

import (
"context"
"io"

"github.com/hatayama/unity-cli-loop/cli/internal/cli"
)

func Run(ctx context.Context, args []string, stdout io.Writer, stderr io.Writer) int {
return cli.RunDispatcher(ctx, args, stdout, stderr)
}
12 changes: 12 additions & 0 deletions cli/internal/projectcli/projectcli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package projectcli

import (
"context"
"io"

"github.com/hatayama/unity-cli-loop/cli/internal/cli"
)

func Run(ctx context.Context, args []string, stdout io.Writer, stderr io.Writer) int {
return cli.RunProjectLocal(ctx, args, stdout, stderr)
}
Loading