larksuite/cli · error

deprecated primary flag must be hidden

Error message

deprecated primary flag must be hidden

What it means

validateInputCLI enforces that a deprecated primary flag must also be hidden, so users are not nagged about a flag they should not adopt while it stays prominently visible. A flag with a deprecation notice but cli hidden=false fails compilation.

Source

Thrown at shortcuts/common/typed_compile_args.go:271

	}
	if supplement.CLI.Hidden {
		if field.cli.Hidden {
			return fmt.Errorf("CLI.Hidden is declared twice")
		}
		field.cli.Hidden = true
	}
	if supplement.CLI.Deprecated != "" {
		if field.cli.Deprecated != "" {
			return fmt.Errorf("CLI.Deprecated is declared twice")
		}
		field.cli.Deprecated = supplement.CLI.Deprecated
	}
	return nil
}

func validateInputCLI(field *compiledInputField) error {
	if field.cli.Deprecated != "" && !field.cli.Hidden {
		return fmt.Errorf("deprecated primary flag must be hidden")
	}
	if field.required && field.defaultValue.Set {
		return fmt.Errorf("required input cannot declare a default")
	}
	if field.defaultValue.Set {
		if err := valueAssignableTo(field.defaultValue.Value, field.valueType); err != nil {
			return fmt.Errorf("default: %w", err)
		}
	}
	seenSources := make(map[typedValueSource]struct{})
	for _, source := range field.cli.ValueSources {
		if source != typedSourceFlag && source != typedSourceFile && source != typedSourceStdin {
			return fmt.Errorf("unknown value source %q", source)
		}
		if _, duplicate := seenSources[source]; duplicate {
			return fmt.Errorf("duplicate value source %q", source)
		}
		seenSources[source] = struct{}{}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Set InputField.CLI.Hidden = true alongside InputField.CLI.Deprecated.
  2. Or add hidden to the cli tag: cli:"deprecated=...,hidden".

Example fix

// before
InputField{CLI: CLI{Deprecated: "use --new"}}
// after
InputField{CLI: CLI{Deprecated: "use --new", Hidden: true}}
Defensive patterns

Strategy: validation

Validate before calling

for _, f := range fields {
    if f.Deprecated != "" && !f.Hidden {
        return fmt.Errorf("flag %s: deprecated flag must also be hidden", f.Name)
    }
}

Prevention

When it happens

Trigger: compileInput -> validateInputCLI when field.cli.Deprecated != "" && !field.cli.Hidden — e.g. cli:"deprecated=..." without hidden, or InputField.CLI.Deprecated set without InputField.CLI.Hidden.

Common situations: Adding a deprecation notice via InputField.CLI.Deprecated and forgetting InputField.CLI.Hidden = true; declaring cli:"deprecated=..." alone in the tag.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/ae1e2193119d9295. Report an issue: GitHub.