Skip to content

feat: support custom type - #141

Merged
kazupon merged 1 commit into
mainfrom
feat/custom
May 26, 2025
Merged

feat: support custom type#141
kazupon merged 1 commit into
mainfrom
feat/custom

Conversation

@kazupon

@kazupon kazupon commented May 26, 2025

Copy link
Copy Markdown
Owner

Description

Linked Issues

kazupon/args-tokens#101

Additional context

Summary by CodeRabbit

  • New Features

    • Documentation now includes detailed guidance and examples for defining custom argument types with user-defined parsing and validation, including usage with libraries like zod.
    • Command-line interface now supports custom argument parsing functions, enabling flexible validation, default values, and multiple value support for custom types.
  • Bug Fixes

    • Default values are now correctly displayed for custom argument types in help and usage information.
  • Tests

    • Added comprehensive tests for custom argument parsing, validation errors, default values, and multiple value support.
  • Chores

    • Added the "zod" library as a new dependency for enhanced schema validation in custom argument parsing.

@coderabbitai

coderabbitai Bot commented May 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update introduces a new parse property for custom argument types in the argument schema, enabling user-defined parsing and validation logic. Documentation and tests are expanded to illustrate usage with libraries like zod, complex data structures, and default values. The CLI usage renderer now recognizes custom types for default value display.

Changes

File(s) Change Summary
docs/guide/essentials/declarative-configuration.md Documents the new parse property for custom argument types, with examples using zod, custom parsing, and kebab-case.
package.json Adds the zod dependency for schema validation in custom argument parsing examples.
src/cli.test.ts Adds tests for custom argument parsing, validation, default values, error handling, and multiple value support.
src/renderer/usage.ts Updates logic to support 'custom' type schemas for default value display in CLI usage help.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant CustomParser
    participant ZodSchema

    User->>CLI: Run command with custom argument(s)
    CLI->>CustomParser: Invoke parse function with input
    CustomParser->>ZodSchema: (Optional) Validate input
    ZodSchema-->>CustomParser: Return validated value or throw error
    CustomParser-->>CLI: Return parsed value or error
    CLI-->>User: Output result or display validation error
Loading

Possibly related PRs

Suggested labels

feature

Poem

In the warren of code, a new path we chart,
Custom parsing now plays a clever part.
With zod at our side, and logic so neat,
Arguments parsed, validation complete!
🥕 Cheers to the devs, for features so grand—
Now custom types hop through CLI land!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kazupon kazupon added the feature Includes new features label May 26, 2025
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying gunshi with  Cloudflare Pages  Cloudflare Pages

Latest commit: 11e875d
Status: ✅  Deploy successful!
Preview URL: https://5947ce05.gunshi.pages.dev
Branch Preview URL: https://feat-custom.gunshi.pages.dev

View logs

@pkg-pr-new

pkg-pr-new Bot commented May 26, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/kazupon/gunshi@141

commit: 11e875d

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/cli.test.ts (1)

969-971: Consider using numeric separators for better readability.

Instead of disabling the eslint rule, consider using numeric separators for the port range constants:

-          // eslint-disable-next-line unicorn/numeric-separators-style
-          if (Number.isNaN(port) || port < 1024 || port > 65535) {
+          if (Number.isNaN(port) || port < 1_024 || port > 65_535) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cee809e and 11e875d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • docs/guide/essentials/declarative-configuration.md (2 hunks)
  • package.json (1 hunks)
  • src/cli.test.ts (2 hunks)
  • src/renderer/usage.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
package.json (1)

159-160:

Details

✅ Verification successful

Verify the zod library version for security and compatibility.

Please ensure that version ^3.25.28 is the latest stable release and check for any known security vulnerabilities.


🌐 Web query:

What is the latest stable version of zod npm package and are there any known security vulnerabilities in version 3.25.28?

💡 Result:

The latest stable version of Zod npm package is 3.25.28, which was released on May 23, 2025, just 2-3 days ago[1][6]. This version is currently tagged as "latest" in the npm registry and has been downloaded over 30 million times in the past week[6].

Regarding security vulnerabilities in version 3.25.28, no direct vulnerabilities have been found for this package according to Snyk's vulnerability database[9]. This means that the core package itself doesn't have any known security issues, though this assessment doesn't include potential vulnerabilities in its dependencies.

It's worth noting that Zod is a TypeScript-first schema declaration and validation library with static type inference[1]. It's widely used for data validation across various projects, particularly in backend development where it helps ensure data contracts are predictable, validated, and fully type-safe[8].

While the stable release is at version 3.25.28, Zod is also working on version 4.0, which is currently in beta. The beta versions include significant changes such as splitting the package into three separate packages: zod, @zod/mini (a tree-shakable variant), and @zod/core (shared logic and parsers)[7]. These beta versions can be installed using the "next" tag.

For developers concerned about security, it's always good practice to regularly update to the latest stable versions and monitor security advisories for any packages used in your projects.

Citations:


Zod version 3.25.28 is the latest stable release with no known security vulnerabilities

  • package.json (lines 159–160)

No upgrade or remediation needed at this time. Continue to monitor the Zod changelog and security advisories for future updates.

src/renderer/usage.ts (1)

315-319: LGTM! Consistent default value display for custom types.

The addition of 'custom' to the type check ensures that custom argument types with default values are properly displayed in the usage output, maintaining consistency with other argument types.

docs/guide/essentials/declarative-configuration.md (2)

166-166: Good addition to the command options documentation.

The parse property is correctly documented as required for custom types, providing clear guidance for users.


200-267: Excellent documentation for custom type arguments!

The section provides comprehensive examples covering various use cases:

  • CSV parsing with array output
  • JSON validation using zod schemas
  • Custom numeric validation with range checking
  • Clear error handling patterns

The examples are practical and demonstrate best practices for implementing custom argument parsers.

src/cli.test.ts (2)

889-1017: Well-structured test suite for custom type arguments!

The test suite comprehensively covers the new custom type functionality with good test cases for CSV parsing, JSON validation with zod, default values, error handling, and multiple values.


2-2:

Details

❓ Verification inconclusive

Verify the zod import path.

The import path 'zod/v4-mini' seems unusual. Typically, zod is imported directly as 'zod'.

Please verify that this specific import path exists and is the intended way to import zod:

Consider using the standard import if the v4-mini path doesn't exist:

-import { z } from 'zod/v4-mini'
+import { z } from 'zod'

🏁 Script executed:

#!/bin/bash
# Description: Check if the zod/v4-mini import path exists in node_modules

# Check if the path exists
fd -t f "v4-mini" node_modules/zod --exec ls -la {} \;

# Check package.json for any exports configuration
cat node_modules/zod/package.json | jq '.exports'

Length of output: 273


Verify zod import path

I wasn’t able to locate a v4-mini subpath in your zod installation—there’s no node_modules/zod folder to confirm an exported v4-mini. Please manually verify that your installed zod package exports "./v4-mini" (e.g. check node_modules/zod/package.json under its exports field). If it’s not present, update the import to the standard entry point:

-import { z } from 'zod/v4-mini'
+import { z } from 'zod'

@kazupon
kazupon merged commit 75b4a0c into main May 26, 2025
@kazupon
kazupon deleted the feat/custom branch May 26, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Includes new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant