Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

refactor!: improve CLI output formatting and help text#190

Merged
quettabit merged 1 commit intomainfrom
qb/polish
Jan 17, 2026
Merged

refactor!: improve CLI output formatting and help text#190
quettabit merged 1 commit intomainfrom
qb/polish

Conversation

@quettabit
Copy link
Member

No description provided.

@quettabit
Copy link
Member Author

@greptileai review this draft

@greptile-apps
Copy link

greptile-apps bot commented Jan 17, 2026

Greptile Summary

This PR refactors CLI output formatting and help text by renaming format enums and their associated types, simplifying function signatures, and improving help documentation. Key changes include: renaming Format to RecordFormat and formatter types (RawFormatterTextFormatter, etc.), restructuring command help text to remove verbose examples, introducing a format_position helper for consistent output, refactoring resolve_time_range to accept a reference instead of individual parameters, and removing redundant comment documentation.

The changes maintain all existing functionality with improved naming clarity. Group constraints in flattened args structures are correctly preserved. However, there is a minor concern about how the Text format variant's clap configuration changed from #[clap(name = "")] to #[clap(alias = "")], which may affect backward compatibility for default format handling.

Confidence Score: 4/5

  • This PR is safe to merge with minor verification needed on clap format alias handling.
  • The refactoring is well-structured with correct type renaming and logic changes. All file analyses show high confidence (4-5/5). The main concern is the change in src/record_format.rs where the Text variant's clap attribute changed from #[clap(name = "")] to #[clap(alias = "")]. This may affect how users specify the default format and could impact backward compatibility. All other changes are straightforward naming/organization improvements with no functional issues. The code is clean, the time range flattening is correct, and the new helper functions improve readability.
  • src/record_format.rs - verify that the clap alias change doesn't break existing users who rely on the default/empty format specification

Important Files Changed

Filename Overview
src/cli.rs Renamed record format enum and restructured help text. Uses #[command(flatten)] to reuse TimeRangeArgs in TimeRangeAndIntervalArgs - constraint groups are preserved by clap. Removed examples from command help (intentional as per PR title). Removed short flag -i from interval (intentional per comments). All formatting updates are correct.
src/main.rs Updated format handling to use new RecordFormat enum names. Introduced format_position helper function for consistent position formatting. Fixed batch_len calculation by using iterator sum instead of loop. Logic for skipping newlines after command records in Text format is correct - command records print to stderr via eprintln! so skipping writer newline is appropriate. All changes align with refactoring goals.
src/record_format.rs Renamed RecordFormat enum variants and updated clap attribute macros. Changed from #[clap(name = "")] to #[clap(alias = "")] for Text variant - this may affect how the empty string is handled as input, potentially changing CLI behavior. Renamed formatter types: RawFormatter→TextFormatter, RawJsonFormatter→JsonFormatter, Base64JsonFormatter→JsonBase64Formatter. Names are more consistent but check if empty string alias affects backward compatibility.
src/ops.rs Refactored resolve_time_range function to accept TimeRangeArgs reference instead of individual parameters. Updated all call sites correctly: passes TimeRangeArgs directly for gauge metrics, passes t.time_range for interval metrics. Simplification is clean and reduces parameter count without breaking functionality.
src/types.rs Reordered Operation enum variants and their corresponding From implementations. Changes are cosmetic/organizational with no functional impact - same variants mapped before and after, just in different order.
src/config.rs Removed comment lines explaining what load_config_file and load_cli_config do. These are purely documentation comments with no functional changes.

Sequence Diagram

sequenceDiagram
    participant User as User CLI
    participant Main as main.rs
    participant RecordFormat as record_format.rs
    participant Ops as ops.rs

    User->>Main: read --format TEXT
    Main->>Ops: read(&s2, args)
    loop For each batch
        Ops-->>Main: SequencedRecord batch
        Main->>RecordFormat: write_record(format=Text)
        alt is_command_record
            RecordFormat->>Main: print to stderr
            Note over Main: skip newline (eprintln adds it)
        else regular record
            RecordFormat->>Main: write to output file
            Main->>Main: write newline
        end
    end
    Main-->>User: formatted output

    User->>Main: get-account-metrics account-ops --interval hour
    Main->>Ops: get_account_metrics(args)
    Ops->>Ops: resolve_time_range(&args.time_range)
    Note over Ops: TimeRangeAndIntervalArgs flattens TimeRangeArgs<br/>Group constraints preserved via clap
    Ops-->>Main: metrics with interval
    Main-->>User: formatted metrics
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@quettabit quettabit force-pushed the qb/polish branch 2 times, most recently from dcab388 to 81cf116 Compare January 17, 2026 23:12
@quettabit
Copy link
Member Author

@greptileai review this draft

@quettabit quettabit changed the title [WIP] refactor!: improve CLI output formatting and help text Jan 17, 2026
@quettabit quettabit marked this pull request as ready for review January 17, 2026 23:29
@quettabit quettabit requested a review from a team as a code owner January 17, 2026 23:29
@quettabit quettabit merged commit 8a413b5 into main Jan 17, 2026
4 checks passed
@quettabit quettabit deleted the qb/polish branch January 17, 2026 23:29
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

#[default]
#[clap(name = "")]
BodyRaw,
#[clap(alias = "")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty string alias #[clap(alias = "")] may not work as expected for clap value enums. Previously used #[clap(name = "")] which explicitly set the name. Verify that users can still use the default/empty variant without specifying a --format value.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/record_format.rs
Line: 23:23

Comment:
**style:** Empty string alias `#[clap(alias = "")]` may not work as expected for clap value enums. Previously used `#[clap(name = "")]` which explicitly set the name. Verify that users can still use the default/empty variant without specifying a `--format` value.

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps greptile-apps bot mentioned this pull request Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant