fix(cli): take global flags after the command, and call --json again
Only --json was taken after the command, so `wait --paused --timeout
60s`, the order the guide's own synopsis and agents use, failed with
"unknown argument '--timeout'", and `-i` after the command did too.
And since that --json was taken as the output flag, `call X --json
'{...}'`, the documented way to pass arguments as JSON, never reached
call: its object then failed as "not key=value".
--timeout, -i and --json now go anywhere on the line; no command has
options of those names. After `call`, a --json followed by an object
is the arguments, and any other --json the output flag. A trailing
--timeout or -i without its value is a usage error that says so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6987033d6b
commit
7574ad5c4e
2 changed files with 23 additions and 4 deletions
|
|
@ -878,13 +878,19 @@ namespace {
|
|||
for (std::size_t i = 0; i < args.size(); ++i) {
|
||||
const std::string_view arg = args[i];
|
||||
if (!options.command.empty()) {
|
||||
// Global flags may follow the command too, before its own.
|
||||
if (arg == "--json") {
|
||||
// Global flags go anywhere, as agents write them: `wait
|
||||
// --paused --timeout 60s`. No command has options of these
|
||||
// names, but for `call --json '{...}'`, its arguments as JSON.
|
||||
const bool callArguments = options.command == "call" && arg == "--json" && i + 1 < args.size() && args[i + 1].starts_with('{');
|
||||
if (arg == "--json" && !callArguments) {
|
||||
options.json = true;
|
||||
continue;
|
||||
}
|
||||
options.rest.emplace_back(arg);
|
||||
continue;
|
||||
if (arg != "--timeout" && arg != "-i" && arg != "--instance") {
|
||||
options.rest.emplace_back(arg);
|
||||
if (callArguments) options.rest.emplace_back(args[++i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ((arg == "-i" || arg == "--instance") && i + 1 < args.size()) {
|
||||
options.instance = args[++i];
|
||||
|
|
@ -897,6 +903,9 @@ namespace {
|
|||
return exitUsage;
|
||||
}
|
||||
options.timeout = *timeout;
|
||||
} else if (arg == "--timeout" || arg == "-i" || arg == "--instance") {
|
||||
*env.err << std::format("crafter-debug: {} needs a value\n", arg);
|
||||
return exitUsage;
|
||||
} else if (arg == "-h" || arg == "--help") {
|
||||
*env.out << usage;
|
||||
return exitOk;
|
||||
|
|
|
|||
Loading…
Reference in a new issue