Skip to content

refactor(cli): extract shared helpers into commands/common module#2359

Open
varshaprasad96 wants to merge 2 commits into
NVIDIA:mainfrom
varshaprasad96:vnarsing/cli-refactor-shared-helpers
Open

refactor(cli): extract shared helpers into commands/common module#2359
varshaprasad96 wants to merge 2 commits into
NVIDIA:mainfrom
varshaprasad96:vnarsing/cli-refactor-shared-helpers

Conversation

@varshaprasad96

Copy link
Copy Markdown
Contributor

Summary

Extract ~950 lines of shared helper functions, types, and parsing utilities from the monolithic run.rs (10,138 lines) into a new commands/common.rs module. This is PR 1 of 6 in the incremental CLI refactor tracked by #2304.

Related Issue

Part of #2304

Changes

  • Create commands/mod.rs and commands/common.rs module scaffolding
  • Move formatting/display helpers: phase_name, format_epoch_ms, format_elapsed, format_timestamp, print_yaml_line, print_sandbox_policy, short_hash, non_empty_or, format_timestamp_ms, format_optional_epoch_ms, truncate_status_field, truncate_display, format_setting_value
  • Move parsing utilities: parse_env_pairs, parse_key_value_pairs, parse_secret_material_env_pairs, parse_credential_*, parse_cli_setting_value, parse_duration_to_ms
  • Move shared types: PolicyGetView, ProvisioningStep, ProvisioningDisplay
  • Move provisioning event handlers, sandbox header, confirm helpers, git env scrubbing
  • Re-export only the 4 items consumed by main.rs and integration tests via pub use in run.rs
  • Use pub(crate) mod commands to keep the module crate-internal

Testing

  • cargo fmt and cargo clippy pass with zero warnings
  • All 362 unit tests pass identically on both baseline and refactored branches
  • CLI --help output byte-identical across all subcommands (gateway, sandbox, provider, service, settings, policy, inference)
  • Integration tests pass

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • No behavioral changes — pure structural refactor

Move shared formatting, parsing, display, and settings helpers from
run.rs into a new commands/common.rs module. run.rs re-exports all
public items so no callers change. This establishes the commands/
directory structure for the incremental run.rs split (NVIDIA#2304).

Signed-off-by: Varsha Prasad Narsing <vnarsing@nvidia.com>
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
…ers extraction

- Remove orphan doc comment left on sandbox_list after print_yaml_line extraction
- Change `pub mod commands` to `pub(crate) mod commands` in lib.rs
- Move 6 unnecessarily pub-exported items to private use imports in run.rs
- Restore stripped rationale comment in parse_cli_setting_value

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@2000krysztof

Copy link
Copy Markdown
Contributor

I'm curious about the decision for placing common.rs under commands/ rather than at the top level of src/. Since run.rs (which is at the parent level) imports from it, and the utilities seem fairly general-purpose, I'm wondering if src/common.rs might be cleaner?

@varshaprasad96

Copy link
Copy Markdown
Contributor Author

@2000krysztof - common.rs is intentionally under commands/ because it's specifically shared helpers for the command modules, not general-purpose crate utilities. The plan in #2304 (#2304 (comment)) calls for decomposing run.rs into commands/gateway.rs, commands/sandbox.rs, commands/provider.rs, etc. common.rs holds the helpers shared across those command modules (CLI parsing, provisioning display, policy views, formatting).

The fact that run.rs currently imports from commands/common is a transitional state, run.rs still contains all the command functions that haven't been extracted yet (PRs 2–6). Once the migration completes, run.rs shrinks to a minimal re-export shim or goes away entirely.

Placing it at src/common.rs would make it a peer of auth.rs, ssh.rs, tls.rs which are infrastructure modules, a different layer than command-specific helpers.

@2000krysztof

Copy link
Copy Markdown
Contributor

Makes sense, thanks for the explanation. Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants