cli: use the defaults for available in the parameter name list

complete_named_params() computes the defaults and then calls the
available callback with the given parameters alone. A parameter that
is available only through a default of another parameter is missing
from the name list, in both spellings, while the command accepts it.

Show the callback the same view as the command does, with a given value
ahead of the default. Reuse the defaults that default_complete() holds.
A parameter with a default stays in the name list until it is given.

No available callback in the tree reads a default yet. Found by
inspection.

Fixes: 248b66b44f ("cli: add OpenWrt CLI")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau committed 2026-11-15 11:17:20 +00:00
1 parent 8176cc82d7
commit 3ae669b656
1 file changed
+3 -5
@@ -279,7 +279,7 @@ function param_available(ctx, spec, argv, named_args)
call(spec.available, spec, ctx.model.scope, ctx, argv, named_args);
}
function complete_named_params(ctx, entry, obj, name, argv, named_params)
function complete_named_params(ctx, entry, obj, name, argv, named_params, defaults)
{
let data = [];
let empty = "";
@@ -289,8 +289,6 @@ function complete_named_params(ctx, entry, obj, name, argv, named_params)
name = substr(name, 1);
}
let defaults = {};
callctx.new(ctx.model, ctx).apply_defaults(obj, defaults);
for (let cur_name in sort(keys(obj))) {
let val = obj[cur_name];
@@ -303,7 +301,7 @@ function complete_named_params(ctx, entry, obj, name, argv, named_params)
if (!val.multiple && named_params[cur_name] != null)
continue;
if (!param_available(ctx, val, argv, named_params))
if (!param_available(ctx, val, argv, { ...defaults, ...named_params }))
continue;
val = {
@@ -441,7 +439,7 @@ function default_complete(ctx, args)
let name = args[0];
if (length(args) == 1)
return complete_named_params(ctx, this, spec, name, base_args, named_args);
return complete_named_params(ctx, this, spec, name, base_args, named_args, defaults);
shift(args);
let cur = spec[name];