feat(cli): discover ThothII projects and installations

This commit is contained in:
2026-08-15 22:24:15 +02:00
parent 4fc03574e1
commit 66614fe8cf
6 changed files with 583 additions and 6 deletions
+42 -6
View File
@@ -22,7 +22,10 @@ import (
"github.com/aritmolab/thothii/tools/tht/internal/workspaceops"
)
const usage = `Usage: tht --installation <absolute-path>/thothii-installation.yaml <command>
const usage = `Usage: tht [--installation <absolute-path>/thothii-installation.yaml] <command>
When --installation is omitted, tht uses THOTHII_INSTALLATION or discovers one valid
descriptor in the current project tree.
Commands:
status Show the Compose service state.
@@ -78,6 +81,23 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
fmt.Fprintf(stderr, "tht: %s\n\n%s", err, usage)
return 2
}
if command == "help" && len(commandArgs) == 0 {
fmt.Fprint(stdout, usage)
return 0
}
if (command == "version" || command == "setup") && len(commandArgs) == 0 {
return commandUsageError(stderr, fmt.Sprintf("unknown command %q", command))
}
workingDirectory, err := os.Getwd()
if err != nil {
fmt.Fprintf(stderr, "tht: current directory is unavailable: %s\n", output.Sanitize(err.Error(), nil))
return 2
}
installationPath, err = config.Resolve(installationPath, os.Getenv, workingDirectory)
if err != nil {
fmt.Fprintf(stderr, "tht: %s\n", output.Sanitize(err.Error(), nil))
return 2
}
installation, err := config.Load(installationPath)
if err != nil {
fmt.Fprintf(stderr, "tht: %s\n", output.Sanitize(err.Error(), nil))
@@ -588,13 +608,29 @@ func piFailure(stderr io.Writer, err error, secretValues []string) int {
}
func parseArgs(args []string) (string, string, []string, error) {
if len(args) < 3 || args[0] != "--installation" {
return "", "", nil, errors.New("--installation <absolute-path> is required before the command")
var installation string
commandArgs := make([]string, 0, len(args))
for index := 0; index < len(args); index++ {
if args[index] != "--installation" {
commandArgs = append(commandArgs, args[index])
continue
}
if index+1 >= len(args) {
return "", "", nil, errors.New("--installation requires an absolute path")
}
if installation != "" {
return "", "", nil, errors.New("--installation may be supplied once")
}
installation = args[index+1]
if !filepath.IsAbs(installation) {
return "", "", nil, errors.New("--installation must be an absolute path")
}
index++
}
if !filepath.IsAbs(args[1]) {
return "", "", nil, errors.New("--installation must be an absolute path")
if len(commandArgs) == 0 {
return "", "", nil, errors.New("a command is required")
}
return args[1], args[2], args[3:], nil
return installation, commandArgs[0], commandArgs[1:], nil
}
func logsArgs(args []string) ([]string, error) {