Added a status command

This commit is contained in:
2026-06-05 17:21:40 -05:00
parent 70483037c9
commit d29d51cede
2 changed files with 76 additions and 1 deletions

37
main.go
View File

@@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"text/tabwriter"
)
func main() {
@@ -71,6 +72,9 @@ func main() {
body, _ := json.Marshal(payload)
sendIPCRequest(cfg, "POST", fmt.Sprintf("/instances/command?name=%s", url.QueryEscape(name)), bytes.NewBuffer(body))
case "list", "status":
fetchAndPrintStatus(cfg)
default:
printUsage()
}
@@ -101,6 +105,39 @@ func sendIPCRequest(cfg *AppConfig, method string, path string, body io.Reader)
fmt.Println(string(respBody))
}
func fetchAndPrintStatus(cfg *AppConfig) {
targetUrl := fmt.Sprintf("http://%s/instances/list", cfg.Daemon.ListenAddress)
resp, err := http.Get(targetUrl)
if err != nil {
log.Fatalf("IPC connection failed. Is the vs-manager daemon running? Error: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
log.Fatalf("Error from daemon: %s", string(respBody))
}
var instances []InstanceStatusResponse
if err := json.NewDecoder(resp.Body).Decode(&instances); err != nil {
log.Fatalf("Failed to decode daemon status matrix: %v", err)
}
if len(instances) == 0 {
fmt.Println("No instances configured yet. Use 'create' to provision one.")
return
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
fmt.Fprintln(w, "INSTANCE NAME\tVERSION\tPORT\tSTATUS")
fmt.Fprintln(w, "-------------\t-------\t----\t------")
for _, inst := range instances {
fmt.Fprintf(w, "%s\t%s\t%d\t%s\n", inst.Name, inst.Version, inst.Port, inst.Status)
}
w.Flush()
}
func printUsage() {
fmt.Println("Vintage Story Server Manager")
fmt.Println("\nUsage:")