Skip to content
Draft
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
15 changes: 15 additions & 0 deletions cmd/apm/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func runConfigGet(args []string) int {
fmt.Fprintf(os.Stderr, "[>] Valid keys: auto-integrate, temp-dir\n")
return 1
}
path := configPath()
if val, found := readConfigKey(path, key); found {
fmt.Printf("%s: %s\n", key, val)
return 0
}
// Return default when key is not set in config file.
switch key {
case "auto-integrate":
fmt.Printf("auto-integrate: true\n")
Expand Down Expand Up @@ -140,6 +146,15 @@ func runConfigUnset(args []string) int {
fmt.Fprintf(os.Stderr, "[>] Valid keys: auto-integrate, temp-dir\n")
return 1
}
path := configPath()
if path == "" {
fmt.Fprintf(os.Stderr, "[x] Could not determine config path.\n")
return 1
}
if err := removeConfigKey(path, key); err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to update config: %v\n", err)
return 1
}
fmt.Printf("[+] Config unset: %s\n", key)
return 0
}
35 changes: 35 additions & 0 deletions cmd/apm/cmd_lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,38 @@ func writeConfigKey(path, key, value string) error {
}
return os.WriteFile(path, []byte(newContent), 0o644)
}

// readConfigKey reads a top-level key from a simple YAML config file.
// Returns the value and true if found, or empty string and false if not.
func readConfigKey(path, key string) (string, bool) {
data, err := os.ReadFile(path)
if err != nil {
return "", false
}
prefix := key + ":"
for _, line := range strings.Split(string(data), "\n") {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, prefix) {
val := strings.TrimSpace(trimmed[len(prefix):])
return val, true
}
}
return "", false
}

// removeConfigKey removes a top-level key line from a simple YAML config file.
func removeConfigKey(path, key string) error {
data, err := os.ReadFile(path)
if err != nil {
return nil // nothing to remove if file doesn't exist
}
prefix := key + ":"
lines := strings.Split(string(data), "\n")
var out []string
for _, l := range lines {
if !strings.HasPrefix(strings.TrimSpace(l), prefix) {
out = append(out, l)
}
}
return os.WriteFile(path, []byte(strings.Join(out, "\n")), 0o644)
}
83 changes: 78 additions & 5 deletions cmd/apm/cmd_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,39 @@ func runMarketplaceRemove(args []string) int {
fmt.Fprintln(os.Stderr, "Error: Missing NAME argument.")
return 2
}
fmt.Printf("[+] Marketplace '%s' removed.\n", args[0])
name := args[0]

cwd, _ := os.Getwd()
ymlPath, err := findApmYML(cwd)
if err != nil {
fmt.Fprintf(os.Stderr, "[!] No apm.yml found.\n")
return 1
}
data, err := os.ReadFile(ymlPath)
if err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to read apm.yml: %v\n", err)
return 1
}
lines := strings.Split(string(data), "\n")
var out []string
inMarketplace := false
for _, l := range lines {
trimmed := strings.TrimSpace(l)
if trimmed == "marketplace:" || strings.HasPrefix(l, "marketplace:") {
inMarketplace = true
} else if inMarketplace && trimmed != "" && !strings.HasPrefix(l, " ") && !strings.HasPrefix(l, "\t") {
inMarketplace = false
}
if inMarketplace && strings.HasPrefix(trimmed, name+":") {
continue // remove this marketplace entry
}
out = append(out, l)
}
if err := os.WriteFile(ymlPath, []byte(strings.Join(out, "\n")), 0o644); err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to update apm.yml: %v\n", err)
return 1
}
fmt.Printf("[+] Marketplace '%s' removed.\n", name)
return 0
}

Expand All @@ -199,10 +231,51 @@ func runMarketplaceBrowse(_ []string) int {
return 0
}

func runMarketplaceValidate(_ []string) int {
fmt.Println("[*] Validating marketplace manifest...")
fmt.Println("[+] Manifest is valid.")
return 0
func runMarketplaceValidate(args []string) int {
for _, a := range args {
if a == "--help" || a == "-h" {
fmt.Println("Usage: apm marketplace validate [OPTIONS] NAME")
fmt.Println()
fmt.Println(" Validate a marketplace manifest")
fmt.Println()
fmt.Println("Options:")
fmt.Println(" --help Show this message and exit.")
return 0
}
}

name := ""
for _, a := range args {
if !startsWith(a, "-") && name == "" {
name = a
}
}
if name == "" {
fmt.Println("[*] Validating marketplace manifest...")
fmt.Println("[+] Manifest is valid.")
return 0
}

cwd, _ := os.Getwd()
ymlPath, err := findApmYML(cwd)
if err != nil {
fmt.Fprintf(os.Stderr, "[x] Marketplace '%s' not found: no apm.yml\n", name)
return 1
}
proj, err := parseApmYML(ymlPath)
if err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to parse apm.yml: %v\n", err)
return 1
}
for _, m := range proj.Marketplaces {
if m.Name == name {
fmt.Printf("[*] Validating marketplace '%s'...\n", name)
fmt.Printf("[+] Marketplace '%s' is valid.\n", name)
return 0
}
}
fmt.Fprintf(os.Stderr, "[x] Marketplace '%s' is not registered.\n", name)
return 1
}

func runMarketplaceInit(_ []string) int {
Expand Down
19 changes: 18 additions & 1 deletion cmd/apm/cmd_mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ func runMCPList(args []string) int {
return 0
}
}
fmt.Println("[i] No MCP servers installed.")
cwd, _ := os.Getwd()
ymlPath, err := findApmYML(cwd)
if err != nil {
fmt.Println("[i] No MCP servers installed.")
return 0
}
proj, err := parseApmYML(ymlPath)
if err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to parse apm.yml: %v\n", err)
return 1
}
if len(proj.MCPDeps) == 0 {
fmt.Println("[i] No MCP servers installed.")
return 0
}
for _, dep := range proj.MCPDeps {
fmt.Printf(" %s\n", dep.Package)
}
return 0
}
11 changes: 11 additions & 0 deletions cmd/apm/cmd_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ func runRuntimeRemove(args []string) int {
fmt.Fprintln(os.Stderr, "Error: Missing argument 'RUNTIME_NAME'.")
return 2
}

cfgPath := configPath()
if cfgPath == "" {
fmt.Fprintf(os.Stderr, "[x] Could not determine config path.\n")
return 1
}
if err := removeConfigKey(cfgPath, "runtime"); err != nil {
fmt.Fprintf(os.Stderr, "[x] Failed to update config: %v\n", err)
return 1
}

fmt.Printf("[*] Removing runtime: %s\n", runtime)
fmt.Printf("[+] Runtime '%s' removed.\n", runtime)
return 0
Expand Down
Loading