Skip to content

Add imports CLI commands and multipart upload support#2

Merged
jjmata merged 4 commits intomainfrom
codex/add-/imports-api-support-in-cli
Feb 6, 2026
Merged

Add imports CLI commands and multipart upload support#2
jjmata merged 4 commits intomainfrom
codex/add-/imports-api-support-in-cli

Conversation

@jjmata
Copy link
Contributor

@jjmata jjmata commented Feb 5, 2026

Motivation

  • Provide CLI support for the /api/v1/imports endpoints so users can list, view, create (file upload) and delete imports from the CLI.
  • Support multipart file uploads from the CLI to allow CSV/OFX/QFX imports to be sent to the API.

Description

  • Add a new imports command group with list, show, create, and delete subcommands in cmd/sure-cli/root/imports_cmd.go that mirror other resource commands and follow dry-run/--apply semantics.
  • Implement create payload construction with file validation and automatic format detection from extension (or explicit --format) in buildImportCreatePayload and prepare form fields for upload.
  • Add PostMultipart helper to the API client in internal/api/client.go to send form data and a file via multipart POST using SetFormData and SetFile.
  • Register the new imports command in the root CLI wiring by adding cmd.AddCommand(newImportsCmd()) in cmd/sure-cli/root/root.go.

Testing

  • No automated tests were executed for these changes.

Codex Task

Summary by CodeRabbit

  • New Features

    • Added imports management command with list, show, create, and delete subcommands
    • List supports filtering by status and account, plus pagination/limit controls
    • Create and delete default to dry-run and use --apply to execute changes
    • File upload for imports with automatic format detection and multipart submission
  • Tests

    • Comprehensive tests for commands and multipart upload behaviors, validations, and error paths

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds a new "imports" Cobra CLI command (list/show/create/delete), integrates it into the root command, and adds multipart upload support to the internal API client to enable file-based import creation (with dry-run vs --apply behavior and input validation).

Changes

Cohort / File(s) Summary
Imports CLI Command
cmd/sure-cli/root/imports_cmd.go
New Cobra command implementing imports with list, show, create, and delete subcommands; supports status/account filtering, pagination, dry-run (--apply), file validation, automatic format detection, and multipart payload construction.
Command Integration
cmd/sure-cli/root/root.go
Wires newImportsCmd() into root command initialization; minor import reorder.
API Client Enhancement
internal/api/client.go
Adds PostMultipart(path string, fields map[string]string, fileField, filePath string, out any) to perform multipart/form-data POSTs (form fields + file), including token refresh and response binding.
Imports CLI Tests
cmd/sure-cli/root/imports_cmd_test.go
Adds tests covering subcommand presence/flags, argument validation, payload build behavior (format detection/override), file existence/type checks, and dry-run vs apply paths.
API Client Tests
internal/api/client_test.go
Adds tests for PostMultipart success path (server validates multipart/form-data and fields) and error paths for mismatched file args.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as Imports CLI
    participant APIClient as API Client
    participant APIServer as API Server

    User->>CLI: run `imports create --apply --file path --source S --account A --file-format F`
    CLI->>CLI: validate flags, check file exists and type, detect/resolve format
    CLI->>CLI: build form fields map and attach file
    CLI->>APIClient: PostMultipart("/api/v1/imports", fields, "file", path)
    APIClient->>APIClient: refresh token if needed
    APIClient->>APIServer: POST /api/v1/imports (multipart/form-data)
    APIServer->>APIClient: 200 / error response
    APIClient->>CLI: parsed response or error
    CLI->>User: print result or failure
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hop through flags and nibble bytes,

Packing CSV carrots in multipart delights.
Dry-run first, then off they go—
A tiny import parade in tow.
🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes in the pull request: adding imports CLI commands and multipart upload support to the API client.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-/imports-api-support-in-cli

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @jjmata, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the CLI by integrating import management capabilities, allowing users to interact with import resources directly from the command line. It also introduces robust file upload support, making it easier to process various financial data formats.

Highlights

  • New CLI Commands for Imports: Introduced a new imports command group with list, show, create, and delete subcommands, providing comprehensive CLI support for managing imports via the /api/v1/imports API endpoints.
  • Multipart File Upload Support: Implemented multipart file upload functionality for the imports create command, enabling users to upload CSV, OFX, or QFX files directly from the CLI. This includes file validation and automatic format detection based on file extension.
  • API Client Enhancement: Added a PostMultipart helper function to the API client to facilitate sending form data and files via multipart POST requests, supporting the new import creation functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cmd/sure-cli/root/imports_cmd.go
    • Added a new file to define the imports Cobra command group.
    • Implemented list subcommand for filtering and paginating imports.
    • Implemented show subcommand for retrieving a single import by ID.
    • Implemented create subcommand with file validation, automatic format detection, and multipart upload logic, supporting dry-run functionality.
    • Implemented delete subcommand for removing imports by ID, also supporting dry-run functionality.
    • Defined importCreateOpts and importCreatePayload structs for command options and payload construction.
  • cmd/sure-cli/root/root.go
    • Registered the new imports command group to the root CLI command structure.
    • Reordered import statements for consistency.
  • internal/api/client.go
    • Added a new PostMultipart method to the Client struct to handle multipart form data and file uploads.
    • Reordered import statements for consistency.
Activity
  • The changes were made to provide CLI support for /api/v1/imports endpoints.
  • The motivation includes supporting multipart file uploads for CSV/OFX/QFX imports.
  • No automated tests were executed for these changes.
  • This PR is linked to a Codex Task for tracking.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces new CLI commands for managing imports, including support for multipart file uploads. The implementation is well-structured, following existing patterns in the CLI. My review focuses on improving error handling and code clarity. I've pointed out several places where errors are ignored, which could lead to silent failures. I've also suggested a more idiomatic way to construct URLs. A major concern is the lack of automated tests for this new functionality, as stated in the PR description. Adding tests would significantly improve the robustness and maintainability of these changes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@internal/api/client.go`:
- Around line 114-129: In Client.PostMultipart validate the file parameters
before building the request: if exactly one of fileField or filePath is
non-empty, return a descriptive error (e.g., via fmt.Errorf or errors.New)
instead of silently omitting the file; keep the ensureFreshToken() check first,
then check the file arguments and only proceed to call SetFile(fileField,
filePath) when both are provided, otherwise fail fast with the clear error so
callers know they passed mismatched file args.

Copy link
Collaborator

@dgilperez dgilperez left a comment

Choose a reason for hiding this comment

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

Good stuff, but there's a flag collision to sort out.

The --format flag here shadows the global output format flag (json|table). This means users can't control output format for this command — breaks CLI consistency.

Rename to --file-format or --import-format and we're good to merge.

🐙🤖

- Rename --format to --file-format to avoid collision with global output flag
- Handle output.Print errors instead of ignoring them
- Panic on MarkFlagRequired error (catches programming mistakes)
- Use url.URL struct for cleaner URL construction
- Validate fileField/filePath consistency in PostMultipart
Copy link
Collaborator

@dgilperez dgilperez left a comment

Choose a reason for hiding this comment

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

Fixed all the issues in commit 7f99352:

--format--file-format (no more collision with global output flag)
output.Print errors now handled
MarkFlagRequired panics on error
• URL construction uses url.URL struct
PostMultipart validates fileField/filePath consistency

Good to merge.

🐙🤖

Copy link
Collaborator

@dgilperez dgilperez left a comment

Choose a reason for hiding this comment

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

Code fixes are in, but this PR still needs tests.

New commands (list, show, create, delete) and the PostMultipart helper should have basic test coverage before merging.

🐙🤖

- imports_cmd_test.go: flag verification, buildImportCreatePayload tests
- client_test.go: PostMultipart multipart upload, mismatched args validation
- Verify --file-format doesn't collide with global --format
Copy link
Collaborator

@dgilperez dgilperez left a comment

Choose a reason for hiding this comment

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

Tests added. All checks pass. Good to merge.

🐙🤖

@jjmata jjmata self-assigned this Feb 6, 2026
@jjmata jjmata merged commit bfc082b into main Feb 6, 2026
3 checks passed
@dgilperez dgilperez deleted the codex/add-/imports-api-support-in-cli branch February 6, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants