fix: Handle unknown flags or sub commands before starting worker#744
Closed
yofabr wants to merge 2 commits intosipeed:mainfrom
Closed
fix: Handle unknown flags or sub commands before starting worker#744yofabr wants to merge 2 commits intosipeed:mainfrom
yofabr wants to merge 2 commits intosipeed:mainfrom
Conversation
Contributor
Author
Collaborator
|
With #429 merged, do you think we still suffer from this issue? |
Contributor
Author
If there is cobra cli merged then this PR can be closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds proper detection and handling for unknown flags and subcommands in the CLI, improving user experience by providing clear error messages instead of silently ignoring invalid arguments.
#671 To properly handle unknown commands instead of starting gateway
Changes
1. Unknown Flag Detection
Added
defaultcase to flag parsing switches in the following commands:--unknown-flagcronAddCmd()for unknown flagsauthLoginCmd()andauthLogoutCmd()for unknown flagsBefore:
picoclaw agent --unknown-flagwould silently ignore the flagAfter:
picoclaw agent --unknown-flagoutputs "Unknown flag: --unknown-flag" and exits with code 12. Flag vs Subcommand Detection
Added checks to distinguish between flags (e.g.,
--debug) and subcommands (e.g.,list,add):Before:
picoclaw cron --debugoutputs "Unknown cron command: --debug"After:
picoclaw cron --debugoutputs "Error: --debug is a flag, not a subcommand"3. Added Import
"strings"import tomain.go,cmd_cron.go, andcmd_auth.gofor prefix checkingBehavior Summary
picoclaw agent --foopicoclaw gateway --foopicoclaw cron add --foopicoclaw auth login --foopicoclaw cron --debugpicoclaw auth -vpicoclaw skills --debugTesting
All changes have been tested manually:
Files Modified
cmd/picoclaw/main.go- Added strings import, flag detection for skillscmd/picoclaw/cmd_agent.go- Added default case for unknown flagscmd/picoclaw/cmd_gateway.go- Converted to switch with default casecmd/picoclaw/cmd_cron.go- Added strings import, flag detection, default casecmd/picoclaw/cmd_auth.go- Added flag detection, default cases