iOfficeAI/OfficeCLI · error · CliException

missing_argument

missing_argument

Error message

Either --type or --from must be specified.

What it means

Thrown by the `add` command when neither --type nor --from is provided. add needs to know what to insert: --type declares a new element kind, --from copies an existing element. With both empty the command has nothing to do, so it fails fast with code `missing_argument` and a Help string.

Source

Thrown at src/officecli/CommandBuilder.Add.cs:127

                else
                {
                    foreach (var kv in unmatchedKvWarnings)
                        Console.Error.WriteLine($"WARNING: Bare property '{kv}' ignored. Did you mean: --prop {kv}");
                    Console.Error.WriteLine("Hint: Properties must be passed with --prop flag, e.g. officecli add <file> <parent> --type picture --prop src=image.png");
                }
            }

            // TreatUnmatchedTokensAsErrors=false exists so the bare key=value
            // warnings above can fire — but it also let a completely unknown
            // `--flag value` pair (e.g. `--at A2`) vanish silently with exit 0,
            // placing the element somewhere the caller did not intend. Any
            // remaining unmatched --option that DetectUnmatchedKeyValues did
            // not claim is a hard error, matching set/get behavior.
            RejectUnknownOptionTokens(result, unmatchedKvWarnings);

            if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(from))
            {
                throw new OfficeCli.Core.CliException("Either --type or --from must be specified.")
                {
                    Code = "missing_argument",
                    Suggestion = "Use --type to specify element type, or --from to copy an existing element.",
                    Help = "officecli add <file> <parent> --type <type> --prop src=<file>"
                };
            }

            // BUG(add-from-prop-silently-ignored): --from copies an existing
            // element verbatim and does not apply --prop overrides. Reject the
            // combination explicitly so users don't think their --prop took
            // effect. Workaround: copy first, then `set` the result path.
            if (!string.IsNullOrEmpty(from) && props != null && props.Length > 0)
            {
                throw new OfficeCli.Core.CliException("--prop cannot be combined with --from; use `set` on the copied path to modify properties.")
                {
                    Code = "invalid_argument",
                    Suggestion = "Run `add --from` first, then `set <new-path> --prop k=v` on the result."
                };

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Add --type with a supported element kind (paragraph, run, table, sheet, row, cell, slide, shape, picture, etc.).
  2. Or use --from to copy an existing element path instead of declaring a type.
  3. Check the add help: `officecli add --help` for the full --type list.

Example fix

# before
officecli add file.docx /body

# after
officecli add file.docx /body --type paragraph
Defensive patterns

Strategy: validation

Validate before calling

// Require type or from before invoking add.
if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(from))
    throw new ArgumentException("add requires --type or --from");

Type guard

// Type guard: add intent is well-defined only with one of these.
static bool HasAddIntent(string? type, string? from) =>
    !string.IsNullOrEmpty(type) || !string.IsNullOrEmpty(from);

Prevention

When it happens

Trigger: `officecli add file.docx /body` with no --type and no --from. The guard at line 125 checks both are null/empty and throws.

Common situations: User forgets the element type entirely; a script drops the --type flag due to an unset variable; an agent assumes a default type exists; the parent path was intended as the only argument but type is mandatory.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/18a78550f571c4b6. Report an issue: GitHub.