Default app name from .miren/app.toml for CLI commands#562
Conversation
Make app delete, route set, and route set-default commands default to the app name from .miren/app.toml when not provided as a positional argument. This maintains backwards compatibility while improving UX when running commands from within an app directory. Commands updated: - app delete: app name is now optional - route set: app name (position 1) is now optional - route set-default: app name is now optional
📝 WalkthroughWalkthroughThree CLI command files (app_delete.go, route_set.go, route_set_default.go) were changed to make the application name optional. The options structs now use Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@cli/commands/app_delete.go`:
- Around line 17-21: The current code calls appconfig.LoadAppConfig() and then
accesses ac.Name without ensuring ac is non-nil, which can panic because
LoadAppConfig may return (nil, nil); update the check in the app deletion logic
to verify ac != nil before referencing ac.Name (i.e., change the condition to
ensure err == nil && ac != nil && ac.Name != "" so appName is only read when ac
is not nil).
In `@cli/commands/route_set_default.go`:
- Around line 16-20: The code in route_set_default.go assumes
appconfig.LoadAppConfig() always returns a non-nil config and dereferences
ac.Name, causing a nil pointer panic when LoadAppConfig returns (nil, nil);
update the conditional that sets appName to first verify ac != nil and ac.Name
!= "" (e.g., if ac, err := appconfig.LoadAppConfig(); err == nil && ac != nil &&
ac.Name != "" { appName = ac.Name }) so you never access ac.Name when ac is nil;
keep the LoadAppConfig call and error handling as-is but add the ac != nil check
around the ac.Name access.
In `@cli/commands/route_set.go`:
- Around line 17-21: LoadAppConfig() can return (nil, nil) and the current code
dereferences ac.Name causing a panic; update the conditional that assigns
appName to ensure ac is not nil before accessing ac.Name (i.e., only set appName
when err == nil && ac != nil && ac.Name != ""), mirroring the nil-check used in
the app_delete logic and using the same symbols LoadAppConfig, ac, and appName
to locate and fix the check.
🧹 Nitpick comments (1)
cli/commands/app_delete.go (1)
11-24: Consider extracting common app name resolution logic.The same fallback pattern (opts → appconfig → error) is duplicated in
app_delete.go,route_set.go, androute_set_default.go. A shared helper function would reduce duplication and ensure consistent behavior.♻️ Example helper function
// In a shared location, e.g., cli/commands/appname.go func resolveAppName(explicit string) (string, error) { if explicit != "" { return explicit, nil } if ac, err := appconfig.LoadAppConfig(); err == nil && ac != nil && ac.Name != "" { return ac.Name, nil } return "", fmt.Errorf("app is required") }
|
^^ Maybe |
LoadAppConfig() returns (nil, nil) when no .miren/app.toml is found. Add nil check before accessing ac.Name to prevent panic.
I'm thinking we do a pass at the app config api writ large. |
Summary
app delete,route set, androute set-defaultcommands default to the app name from.miren/app.tomlwhen not provided as a positional argumentTest plan
make lintpasseshack/it ./cli/commands/...tests pass.miren/app.tomlwithname = "testapp"m route set example.com(should use testapp)m route set-default(should use testapp)m app delete(should prompt for testapp)