larksuite/cli · error

CLI.Encoding is declared by both cli tag and InputField.CLI

Error message

CLI.Encoding is declared by both cli tag and InputField.CLI

What it means

mergeInputSupplement: the field already declares a cli-tag encoding and the InputField.CLI supplement also supplies Encoding - the two authoring surfaces are mutually exclusive per attribute to avoid ambiguity.

Source

Thrown at shortcuts/common/typed_compile_args.go:250

			return fmt.Errorf("required input cannot declare a default")
		}
		field.defaultValue = supplement.Default
	}
	if len(supplement.CLI.Aliases) > 0 {
		if len(field.cli.Aliases) > 0 {
			return fmt.Errorf("CLI.Aliases is declared by both cli tag and InputField.CLI")
		}
		field.cli.Aliases = append([]typedFlagAlias(nil), supplement.CLI.Aliases...)
	}
	if len(supplement.CLI.ValueSources) > 0 {
		if len(field.cli.ValueSources) > 0 {
			return fmt.Errorf("CLI.ValueSources is declared by both cli tag and InputField.CLI")
		}
		field.cli.ValueSources = append([]typedValueSource(nil), supplement.CLI.ValueSources...)
	}
	if supplement.CLI.Encoding != "" {
		if field.cli.Encoding != "" {
			return fmt.Errorf("CLI.Encoding is declared by both cli tag and InputField.CLI")
		}
		field.cli.Encoding = supplement.CLI.Encoding
	}
	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
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Remove encoding= from the cli tag and set InputField.CLI.Encoding only.
  2. Or clear InputField.CLI.Encoding if the tag declaration is authoritative.

Example fix

// before
Payload string `flag:"payload" cli:"encoding=json"` + InputField{CLI: CLI{Encoding: "json"}}
// after
Payload string `flag:"payload"` + InputField{CLI: CLI{Encoding: "json"}}
Defensive patterns

Strategy: validation

Validate before calling

for _, f := range fields {
    if f.TagEncoding != "" && f.InputEncoding != "" {
        return fmt.Errorf("flag %s: encoding declared twice", f.Name)
    }
}

Prevention

When it happens

Trigger: compileInput -> mergeInputSupplement when supplement.CLI.Encoding != "" and field.cli.Encoding != "" (parsed from the cli tag).

Common situations: Setting encoding=json programmatically on a field that already has cli:"encoding=json" in its tag after copying configuration between declaration styles.

Related errors


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