iOfficeAI/OfficeCLI · error · CliException

missing_argument

missing_argument

Error message

Either --file or --stdin must be specified

What it means

The import command needs CSV/TSV content from either a --file/--source path or --stdin. This fires when neither was supplied, so there is nothing to import.

Source

Thrown at src/officecli/CommandBuilder.Import.cs:83

                // StripBom for the same reason batch does it: File.ReadAllText
                // (the --file branch below) drops a UTF-8 BOM implicitly, the
                // stdin reader hands it through. Without this, `import --stdin`
                // fed a BOM'd CSV put a stray U+FEFF inside the first header
                // cell while `import --file` on the same bytes did not.
                csvContent = StripBom(StdIn.ReadToEnd());
            }
            else if (source != null)
            {
                if (!source.Exists)
                    throw new CliException($"Source file not found: {source.FullName}")
                    {
                        Code = "file_not_found"
                    };
                csvContent = File.ReadAllText(source.FullName, Encoding.UTF8);
            }
            else
            {
                throw new CliException("Either --file or --stdin must be specified")
                {
                    Code = "missing_argument",
                    Suggestion = "Use --file <path> to specify a CSV/TSV file, or --stdin to read from standard input"
                };
            }

            // Determine delimiter: --format flag > file extension > default csv
            char delimiter = ',';
            if (!string.IsNullOrEmpty(format))
            {
                delimiter = format.ToLowerInvariant() switch
                {
                    "tsv" => '\t',
                    "csv" => ',',
                    _ => throw new CliException($"Unknown format: {format}. Use 'csv' or 'tsv'")
                    {
                        Code = "invalid_value",
                        ValidValues = ["csv", "tsv"]

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Add --file <path> to read a CSV/TSV file.
  2. Or pipe data and add --stdin: 'cat data.csv | officecli import out.xlsx --stdin'.
  3. Ensure at least one of the two is always present in automation.

Example fix

// before
officecli import out.xlsx
// after
officecli import out.xlsx --file data.csv
# or
cat data.csv | officecli import out.xlsx --stdin
Defensive patterns

Strategy: validation

Validate before calling

if (sourcePath is null && !Console.IsInputRedirected)
    throw new ArgumentException(
        "Import needs --file <path> or piped --stdin.");

Prevention

When it happens

Trigger: 'officecli import out.xlsx' with no --file and no --stdin (e.g. in an interactive shell with no pipe).

Common situations: Forgetting the source flag in a script; assuming import reads a default file; a closed pipe with the flag also absent.

Related errors


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