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
53 changes: 0 additions & 53 deletions cli/common/clicore/cli_vibe_test.go

This file was deleted.

10 changes: 2 additions & 8 deletions cli/common/clicore/string_helpers.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package clicore

import "strings"
import "github.com/hatayama/unity-cli-loop/common/tooldocs"

func FirstHelpLine(description string) string {
for _, line := range strings.Split(description, "\n") {
trimmed := strings.TrimSpace(line)
if trimmed != "" {
return trimmed
}
}
return ""
return tooldocs.FirstHelpLine(description)
}

func FirstNonEmpty(values ...string) string {
Expand Down
43 changes: 43 additions & 0 deletions cli/common/clicore/tooldocs_aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package clicore

import "github.com/hatayama/unity-cli-loop/common/tooldocs"

const (
DynamicCodeFileFlagName = tooldocs.DynamicCodeFileFlagName
DynamicCodeFileOptionName = tooldocs.DynamicCodeFileOptionName
DynamicCodeFileOptionUsage = tooldocs.DynamicCodeFileOptionUsage
DynamicCodeFileOptionDescription = tooldocs.DynamicCodeFileOptionDescription

ProjectPathFlagName = tooldocs.ProjectPathFlagName
ReloadExternalSceneChangesPropertyName = tooldocs.ReloadExternalSceneChangesPropertyName
)

type OptionHelpEntry = tooldocs.OptionHelpEntry

func VisibleOptionHelpEntriesForTool(tool ToolDefinition) []OptionHelpEntry {
return tooldocs.VisibleOptionHelpEntriesForTool(tool)
}

func FindProperty(tool ToolDefinition, kebabName string) (string, ToolProperty, bool, bool) {
return tooldocs.FindProperty(tool, kebabName)
}

func OptionNameForProperty(toolName string, propertyName string, property ToolProperty) string {
return tooldocs.OptionNameForProperty(toolName, propertyName, property)
}

func VisibleOptionNamesForTool(tool ToolDefinition) []string {
return tooldocs.VisibleOptionNamesForTool(tool)
}

func IsBooleanProperty(property ToolProperty) bool {
return tooldocs.IsBooleanProperty(property)
}

func IsNegatedBooleanProperty(property ToolProperty) bool {
return tooldocs.IsNegatedBooleanProperty(property)
}

func OptionSummary(toolName string, propertyName string, property ToolProperty) string {
return tooldocs.OptionSummary(toolName, propertyName, property)
}
26 changes: 26 additions & 0 deletions cli/common/clicore/ui_aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package clicore

import (
"io"

"github.com/hatayama/unity-cli-loop/common/ui"
"github.com/hatayama/unity-cli-loop/common/unityipc"
)

type TerminalSpinner = ui.TerminalSpinner

func NewToolSpinner(stderr io.Writer, command string) *TerminalSpinner {
return ui.NewToolSpinner(stderr, shouldShowToolFeedback(command))
}

func NewLaunchSpinner(stdout io.Writer, stderr io.Writer) *TerminalSpinner {
return ui.NewLaunchSpinner(stdout, stderr)
}

func NewSpinnerProgressFunc(spinner *TerminalSpinner, executingMessage string) unityipc.ProgressFunc {
return ui.NewSpinnerProgressFunc(spinner, executingMessage)
}

func shouldShowToolFeedback(command string) bool {
return command != ExecuteDynamicCodeCommandName
}
27 changes: 27 additions & 0 deletions cli/common/clicore/vibelog_aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package clicore

import "github.com/hatayama/unity-cli-loop/common/vibelog"

const (
CLIVibeLogDirectory = vibelog.CLIVibeLogDirectory
CLIVibeLogPrefix = vibelog.CLIVibeLogPrefix
CLIVibeLogEnvName = vibelog.CLIVibeLogEnvName
)

type CLIVibeLogEntry = vibelog.CLIVibeLogEntry

func NewCLIVibeCorrelationID() string {
return vibelog.NewCLIVibeCorrelationID()
}

func WriteCLIVibeLog(projectRoot string, entry CLIVibeLogEntry) error {
return vibelog.WriteCLIVibeLog(projectRoot, entry)
}

func IsCLIVibeLogEnabled() bool {
return vibelog.IsCLIVibeLogEnabled()
}

func ProjectIdentity(projectRoot string) string {
return vibelog.ProjectIdentity(projectRoot)
}
28 changes: 28 additions & 0 deletions cli/common/clicore/vibelog_test_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package clicore

import (
"os"
"path/filepath"
"testing"
)

func enableCliVibeLog(t *testing.T) {
t.Helper()
t.Setenv(CLIVibeLogEnvName, "1")
}

func readOnlyCliVibeLog(t *testing.T, projectRoot string) string {
t.Helper()
logFiles, err := filepath.Glob(filepath.Join(projectRoot, CLIVibeLogDirectory, CLIVibeLogPrefix+"_*.json"))
if err != nil {
t.Fatalf("failed to glob CLI Vibe logs: %v", err)
}
if len(logFiles) != 1 {
t.Fatalf("expected one CLI Vibe log, got %d: %#v", len(logFiles), logFiles)
}
content, err := os.ReadFile(logFiles[0])
if err != nil {
t.Fatalf("failed to read CLI Vibe log: %v", err)
}
return string(content)
}
13 changes: 13 additions & 0 deletions cli/common/tooldocs/string_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tooldocs

import "strings"

func FirstHelpLine(description string) string {
Comment thread
hatayama marked this conversation as resolved.
for _, line := range strings.Split(description, "\n") {
trimmed := strings.TrimSpace(line)
if trimmed != "" {
return trimmed
}
}
return ""
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package clicore
package tooldocs

import (
"fmt"
"sort"
"strings"

"github.com/hatayama/unity-cli-loop/common/tools"
)

// --code-file is CLI-side sugar for execute-dynamic-code: it loads a C# source file into
Expand All @@ -17,14 +19,20 @@ const (

const DynamicCodeFileOptionDescription = "Read C# code from a file instead of --code when shell quoting would alter multiline code"

const (
compileCommandName = "compile"
executeDynamicCodeCommandName = "execute-dynamic-code"
runTestsCommandName = "run-tests"
)

// OptionHelpEntry is one row of a tool's --help option listing.
type OptionHelpEntry struct {
Name string
Usage string
Description string
}

func VisibleOptionHelpEntriesForTool(tool ToolDefinition) []OptionHelpEntry {
func VisibleOptionHelpEntriesForTool(tool tools.ToolDefinition) []OptionHelpEntry {
schema := tool.EffectiveInputSchema()
entries := make([]OptionHelpEntry, 0, len(schema.Properties))
for propertyName, property := range schema.Properties {
Expand All @@ -47,14 +55,14 @@ func VisibleOptionHelpEntriesForTool(tool ToolDefinition) []OptionHelpEntry {
return entries
}

func optionUsage(optionName string, property ToolProperty) string {
func optionUsage(optionName string, property tools.ToolProperty) string {
if IsBooleanProperty(property) {
return optionName
}
return optionName + " <" + optionValueName(property) + ">"
}

func optionValueName(property ToolProperty) string {
func optionValueName(property tools.ToolProperty) string {
switch strings.ToLower(property.Type) {
case "integer":
return "integer"
Expand All @@ -69,7 +77,7 @@ func optionValueName(property ToolProperty) string {
}
}

func optionDescription(toolName string, propertyName string, property ToolProperty) string {
func optionDescription(toolName string, propertyName string, property tools.ToolProperty) string {
if isRunTestsSaveBeforeRunOption(toolName, propertyName, property) {
return OptionSummary(toolName, propertyName, property) + "; default: auto-save enabled"
}
Expand Down Expand Up @@ -100,7 +108,7 @@ func defaultValueText(value any) string {
return fmt.Sprint(value)
}

func OptionSummary(toolName string, propertyName string, property ToolProperty) string {
func OptionSummary(toolName string, propertyName string, property tools.ToolProperty) string {
if IsNegatedBooleanProperty(property) {
if isRunTestsSaveBeforeRunOption(toolName, propertyName, property) {
return "Fail before execution if unsaved editor changes remain instead of auto-saving them"
Expand All @@ -118,8 +126,8 @@ func OptionSummary(toolName string, propertyName string, property ToolProperty)
return FirstHelpLine(property.Description)
}

func appendDynamicCodeFileOptionName(tool ToolDefinition, options []string) []string {
if tool.Name != ExecuteDynamicCodeCommandName {
func appendDynamicCodeFileOptionName(tool tools.ToolDefinition, options []string) []string {
if tool.Name != executeDynamicCodeCommandName {
return options
}
for _, option := range options {
Expand All @@ -130,8 +138,8 @@ func appendDynamicCodeFileOptionName(tool ToolDefinition, options []string) []st
return append(options, DynamicCodeFileOptionName)
}

func appendDynamicCodeFileOptionHelpEntry(tool ToolDefinition, entries []OptionHelpEntry) []OptionHelpEntry {
if tool.Name != ExecuteDynamicCodeCommandName {
func appendDynamicCodeFileOptionHelpEntry(tool tools.ToolDefinition, entries []OptionHelpEntry) []OptionHelpEntry {
if tool.Name != executeDynamicCodeCommandName {
return entries
}
for _, entry := range entries {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package clicore
package tooldocs

import (
"sort"
"strings"

"github.com/hatayama/unity-cli-loop/common/tools"
)

const (
ProjectPathFlagName = "project-path"
ReloadExternalSceneChangesPropertyName = "ReloadExternalSceneChanges"
)

func FindProperty(tool ToolDefinition, kebabName string) (string, ToolProperty, bool, bool) {
func FindProperty(tool tools.ToolDefinition, kebabName string) (string, tools.ToolProperty, bool, bool) {
schema := tool.EffectiveInputSchema()
for propertyName, property := range schema.Properties {
if OptionNameForProperty(tool.Name, propertyName, property) == kebabName {
return propertyName, property, IsNegatedBooleanProperty(property), true
}
}
return "", ToolProperty{}, false, false
return "", tools.ToolProperty{}, false, false
}

func OptionNameForProperty(toolName string, propertyName string, property ToolProperty) string {
func OptionNameForProperty(toolName string, propertyName string, property tools.ToolProperty) string {
kebabName := pascalToKebab(propertyName)
if IsNegatedBooleanProperty(property) {
if isRunTestsSaveBeforeRunOption(toolName, propertyName, property) {
Expand All @@ -34,19 +36,19 @@ func OptionNameForProperty(toolName string, propertyName string, property ToolPr
return kebabName
}

func isRunTestsSaveBeforeRunOption(toolName string, propertyName string, property ToolProperty) bool {
return toolName == RunTestsCommandName &&
func isRunTestsSaveBeforeRunOption(toolName string, propertyName string, property tools.ToolProperty) bool {
return toolName == runTestsCommandName &&
propertyName == "SaveBeforeRun" &&
IsNegatedBooleanProperty(property)
}

func isCompileReloadExternalSceneChangesOption(toolName string, propertyName string, property ToolProperty) bool {
return toolName == CompileCommandName &&
func isCompileReloadExternalSceneChangesOption(toolName string, propertyName string, property tools.ToolProperty) bool {
return toolName == compileCommandName &&
propertyName == ReloadExternalSceneChangesPropertyName &&
IsNegatedBooleanProperty(property)
}

func VisibleOptionNamesForTool(tool ToolDefinition) []string {
func VisibleOptionNamesForTool(tool tools.ToolDefinition) []string {
schema := tool.EffectiveInputSchema()
options := make([]string, 0, len(schema.Properties))
for propertyName, property := range schema.Properties {
Expand All @@ -60,11 +62,11 @@ func VisibleOptionNamesForTool(tool ToolDefinition) []string {
return options
}

func IsBooleanProperty(property ToolProperty) bool {
func IsBooleanProperty(property tools.ToolProperty) bool {
return strings.EqualFold(property.Type, "boolean")
}

func IsNegatedBooleanProperty(property ToolProperty) bool {
func IsNegatedBooleanProperty(property tools.ToolProperty) bool {
defaultValue, ok := property.EffectiveDefault().(bool)
return IsBooleanProperty(property) && ok && defaultValue
}
Expand Down
Loading
Loading