use cwd to find container
This commit is contained in:
parent
ed8a6f2d81
commit
c59527c8d8
1 changed files with 40 additions and 16 deletions
56
commands.go
56
commands.go
|
@ -8,6 +8,39 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func getContainerForCurrentDirectory() (string, error) {
|
||||
// Get all hako containers
|
||||
output, err := runCommandOutput("docker", "ps", "-a", "--filter", "name=hako-", "--format", "{{.Names}}")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
containers := strings.Split(strings.TrimSpace(output), "\n")
|
||||
if len(containers) == 0 || containers[0] == "" {
|
||||
return "", fmt.Errorf("no hako containers found")
|
||||
}
|
||||
|
||||
// Try to find containers that match any supported language for the current directory
|
||||
supportedLangs := []string{"go", "py", "python"}
|
||||
|
||||
for _, lang := range supportedLangs {
|
||||
expectedName, err := getProjectContainerName(lang)
|
||||
if err != nil {
|
||||
continue // Skip if we can't generate a name for this language
|
||||
}
|
||||
|
||||
// Check if this expected container name exists in our list
|
||||
for _, container := range containers {
|
||||
if strings.TrimSpace(container) == expectedName {
|
||||
return expectedName, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no exact match found, return the first container as fallback
|
||||
return strings.TrimSpace(containers[0]), nil
|
||||
}
|
||||
|
||||
func initCommand(lang string) error {
|
||||
if lang == "" {
|
||||
fmt.Println("Building base hako image...")
|
||||
|
@ -80,16 +113,12 @@ func downCommand(container string) error {
|
|||
if container != "" {
|
||||
containerName = container
|
||||
} else {
|
||||
// Find any hako container for current project
|
||||
output, err := runCommandOutput("docker", "ps", "-a", "--filter", "name=hako-", "--format", "{{.Names}}")
|
||||
// Find the appropriate hako container for current directory
|
||||
var err error
|
||||
containerName, err = getContainerForCurrentDirectory()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("no hako containers found for current project: %v", err)
|
||||
}
|
||||
containers := strings.Split(strings.TrimSpace(output), "\n")
|
||||
if len(containers) == 0 || containers[0] == "" {
|
||||
return fmt.Errorf("no hako containers found for current project")
|
||||
}
|
||||
containerName = containers[0] // Use first found container
|
||||
}
|
||||
|
||||
if !containerExists(containerName) {
|
||||
|
@ -130,16 +159,11 @@ func psCommand() error {
|
|||
}
|
||||
|
||||
func syncCommand() error {
|
||||
// TODO use the container for the currently working directory instead of just the first one in the filter...
|
||||
output, err := runCommandOutput("docker", "ps", "-a", "--filter", "name=hako-", "--format", "{{.Names}}")
|
||||
// Find the appropriate hako container for current directory
|
||||
containerName, err := getContainerForCurrentDirectory()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("no hako containers found for current project: %v", err)
|
||||
}
|
||||
containers := strings.Split(strings.TrimSpace(output), "\n")
|
||||
if len(containers) == 0 || containers[0] == "" {
|
||||
return fmt.Errorf("no hako containers found for current project")
|
||||
}
|
||||
containerName := containers[0] // Use first found container
|
||||
|
||||
if !containerExists(containerName) {
|
||||
return fmt.Errorf("container %s does not exist", containerName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue