Skip to content

CLI: -j/--json produces no output, and --output-dir is ignored in JSON mode #32

Description

@jrzmurray

Running the CLI with -j / --json produces no output at all, and --output-dir is ignored in that mode.

Repro

$ pyonenote -j -f Section.one -o out/
$ echo "exit=$?  stdout=(empty)  out/=(empty)"
exit=0  stdout=(empty)  out/=(empty)

The file is parsed successfully — the JSON is built and then discarded.

1. -j prints nothing

process_onenote_file() builds the JSON and returns it:

https://github.com/DissectMalware/pyOneNote/blob/main/pyOneNote/Main.py#L75

    return json.dumps(data)

but the only caller never captures or prints the return value:

https://github.com/DissectMalware/pyOneNote/blob/main/pyOneNote/Main.py#L100

        process_onenote_file(file, args.output_dir, args.extension, args.json)

So with -j, the human-readable dump is correctly suppressed, the JSON is correctly generated — and then nothing is emitted.

I realize the return value is the contract for library consumers (process_onenote_file() is imported and used that way), and that part works fine. This is purely about the CLI surface: the flag is advertised as "Generate JSON output only, no dumps or prints", but as a CLI flag it currently has no observable effect.

2. --output-dir is not honored under -j

The only use of output_dir is the embedded-file extraction loop, which sits inside if not json_output::

https://github.com/DissectMalware/pyOneNote/blob/main/pyOneNote/Main.py#L30

So in JSON mode nothing is written to --output-dir — not the extracted files, and not the JSON either. Passing -o alongside -j silently does nothing.

Possible directions

Either would resolve (1); (2) depends on which you consider correct:

  • Emit on stdoutif args.json: print(result). Keeps -j pipeable (| jq), and leaves --output-dir legitimately unused in JSON mode (consistent with "no dumps"). Smallest change.
  • Write to --output-dir — e.g. <output_dir>/<section>.json, which would make -o behave consistently across modes. Note -o defaults to "./", so distinguishing "user passed -o" from the default would need a sentinel default.

Happy to send a PR for whichever you prefer — or feel free to close if the CLI -j behavior is intentional and the library return value is the only supported path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions