Skip to content

docs(guide): use define function - #424

Merged
kazupon merged 6 commits into
kazupon:mainfrom
ryoppippi:docs/use-define-helper
Dec 10, 2025
Merged

kazupon merged 6 commits into
kazupon:mainfrom
ryoppippi:docs/use-define-helper

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Description

use define function for defining CLI command every time.
this force llms to use define function

Linked Issues

Additional context

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced define function for declaratively creating commands with improved type safety and structured syntax.
  • Documentation

    • Updated all guides and examples across getting started, essentials, advanced topics, and plugin development to demonstrate the new define() command definition pattern.

✏️ Tip: You can customize this high-level summary in your review settings.

Updated code examples in the getting-started guide to use the define()
helper function for command definitions instead of plain object literals.

This change:
- Adds define import from gunshi
- Wraps command object with define() call
- Maintains consistency with recommended best practices

The example now demonstrates the proper way to define commands from the
start, helping new users adopt the correct pattern immediately.
Updated all code examples in the declarative configuration guide to use
the define() helper function instead of plain object literals.

This comprehensive update covers:
- Basic command structure examples
- Complete working examples
- Positional argument definitions
- Custom type argument examples
- Kebab-case conversion examples
- Conflicting options examples
- Examples with dynamic/async features
- Explicit argument tracking examples

Each example now demonstrates the recommended pattern of wrapping command
definitions with define(), ensuring consistency across all documentation
and helping users understand the proper command definition approach.
Updated the command hooks guide to use define() helper for command
definition instead of inline object literal.

This change:
- Extracts command definition from cli() call
- Uses define() to wrap command object
- Improves code clarity by separating command definition from hook setup

The refactored example better demonstrates separation of concerns,
showing hooks configuration distinct from command definition.
Updated the internationalization guide's built-in resources example to
use the define() helper function for command definition.

This change:
- Adds define import to the example
- Wraps command object with define()
- Maintains consistency with other documentation examples

The example now shows the proper pattern for defining commands when
using built-in translation resources from @gunshi/resources package.
Updated the plugin usage template in guidelines to use define() helper
for command definition instead of plain object literal.

This change:
- Adds define import to the template code
- Wraps command object with define()
- Provides correct pattern for plugin usage examples

Plugin developers using this template will now see the recommended
approach for defining commands when integrating their plugins.
Updated all plugin testing examples to use define() helper for creating
mock command objects instead of plain object literals.

This change:
- Adds define import to test file examples
- Wraps all mock command objects with define()
- Maintains consistency with production code patterns

Changes cover multiple testing scenarios:
- Basic plugin initialization tests
- Configuration validation tests
- Extension factory tests
- Extension method interaction tests
- Async extension tests
- Plugin dependency tests
- Plugin interaction tests

Using define() in tests ensures test code follows the same patterns as
production code, making tests more representative and maintainable.
@coderabbitai

coderabbitai Bot commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR updates documentation examples across multiple guide sections to adopt the new define() API for command construction, replacing inline command object literals and adjusting CLI usage patterns accordingly.

Changes

Cohort / File(s) Summary
Advanced Guides
packages/docs/src/guide/advanced/command-hooks.md, packages/docs/src/guide/advanced/internationalization.md
Updated examples to import define from gunshi and wrap command definitions with define({ ... }) instead of plain objects
Essentials Guides
packages/docs/src/guide/essentials/declarative.md, packages/docs/src/guide/essentials/getting-started.md
Added define import and replaced all object-based command definitions with define({ ... }) wrapper across code samples
Plugin Guides
packages/docs/src/guide/plugin/guidelines.md, packages/docs/src/guide/plugin/testing.md
Updated examples to import and use define(...) factory function for command construction instead of plain objects

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

  • All changes follow a consistent, repetitive pattern (add define import, wrap command objects)
  • No logic modifications or behavioral changes to the underlying code
  • Documentation-only updates showing consistent API usage across multiple examples

Possibly related PRs

  • feat: command lifecycle hooks #212 — The main PR's docs changes align with code changes that add cli overloads accepting an entry command as the second parameter and introduce lifecycle hooks on CliOptions.
  • fix: improve type-safe #330 — Both PRs touch the same define command-definition API exports and usage patterns from gunshi.
  • docs: ready for v0.27 #275 — Overlapping documentation and public-API surface changes around the new define(...) API and v0.27 docs.

Suggested labels

documentation

Suggested reviewers

  • kazupon

Poem

🐰 With define wrapped tight and neat,
Commands now feel complete,
Where object literals used to roam,
Our CLI finds a cleaner home! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: updating documentation to consistently use the define function for CLI command definitions across multiple guide files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@pkg-pr-new

pkg-pr-new Bot commented Dec 8, 2025

Copy link
Copy Markdown

Open in StackBlitz

@gunshi/bone

npm i https://pkg.pr.new/@gunshi/bone@424

@gunshi/definition

npm i https://pkg.pr.new/@gunshi/definition@424

@gunshi/docs

npm i https://pkg.pr.new/@gunshi/docs@424

gunshi

npm i https://pkg.pr.new/gunshi@424

@gunshi/plugin

npm i https://pkg.pr.new/@gunshi/plugin@424

@gunshi/plugin-completion

npm i https://pkg.pr.new/@gunshi/plugin-completion@424

@gunshi/plugin-dryrun

npm i https://pkg.pr.new/@gunshi/plugin-dryrun@424

@gunshi/plugin-global

npm i https://pkg.pr.new/@gunshi/plugin-global@424

@gunshi/plugin-i18n

npm i https://pkg.pr.new/@gunshi/plugin-i18n@424

@gunshi/plugin-renderer

npm i https://pkg.pr.new/@gunshi/plugin-renderer@424

@gunshi/resources

npm i https://pkg.pr.new/@gunshi/resources@424

@gunshi/shared

npm i https://pkg.pr.new/@gunshi/shared@424

commit: 5bc037d

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f62f6f4 and 5bc037d.

📒 Files selected for processing (6)
  • packages/docs/src/guide/advanced/command-hooks.md (1 hunks)
  • packages/docs/src/guide/advanced/internationalization.md (1 hunks)
  • packages/docs/src/guide/essentials/declarative.md (24 hunks)
  • packages/docs/src/guide/essentials/getting-started.md (2 hunks)
  • packages/docs/src/guide/plugin/guidelines.md (1 hunks)
  • packages/docs/src/guide/plugin/testing.md (12 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: kazupon/gunshi PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T09:55:04.596Z
Learning: Update documentation at gunshi.dev when adding new features or changing APIs
📚 Learning: 2025-12-05T09:55:04.596Z
Learnt from: CR
Repo: kazupon/gunshi PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T09:55:04.596Z
Learning: Applies to packages/plugin-*/src/**/*.ts : Implement plugins using gunshi/plugin package for minimal dependencies following the plugin API in packages/plugin/src/

Applied to files:

  • packages/docs/src/guide/plugin/guidelines.md
  • packages/docs/src/guide/plugin/testing.md
  • packages/docs/src/guide/advanced/internationalization.md
📚 Learning: 2025-12-05T09:55:04.596Z
Learnt from: CR
Repo: kazupon/gunshi PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T09:55:04.596Z
Learning: Update documentation at gunshi.dev when adding new features or changing APIs

Applied to files:

  • packages/docs/src/guide/plugin/guidelines.md
  • packages/docs/src/guide/advanced/command-hooks.md
  • packages/docs/src/guide/plugin/testing.md
  • packages/docs/src/guide/essentials/getting-started.md
  • packages/docs/src/guide/advanced/internationalization.md
  • packages/docs/src/guide/essentials/declarative.md
📚 Learning: 2025-12-05T09:55:04.596Z
Learnt from: CR
Repo: kazupon/gunshi PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T09:55:04.596Z
Learning: Applies to packages/plugin/src/**/*.ts : Provide type helpers for plugin developers such as GunshiParams, CommandContext, etc.

Applied to files:

  • packages/docs/src/guide/plugin/guidelines.md
  • packages/docs/src/guide/advanced/command-hooks.md
  • packages/docs/src/guide/plugin/testing.md
  • packages/docs/src/guide/advanced/internationalization.md
  • packages/docs/src/guide/essentials/declarative.md
📚 Learning: 2025-12-05T09:55:04.596Z
Learnt from: CR
Repo: kazupon/gunshi PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T09:55:04.596Z
Learning: Applies to packages/gunshi/src/**/*.ts : Test changes across all supported runtimes (Node.js, Deno, Bun) when modifying core functionality

Applied to files:

  • packages/docs/src/guide/plugin/testing.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test on Node.js 20
🔇 Additional comments (9)
packages/docs/src/guide/plugin/testing.md (2)

54-73: define() import and usage correctly applied.

The import of define from gunshi and its usage to wrap command objects is consistent with the pattern shown throughout this PR. The mock command construction using define() is correct.


156-165: Consistent define() usage across test examples.

All test examples that create mock commands correctly use define({ ... }) pattern. The integration with createCommandContext and vi.fn() mocks is properly maintained. This provides clear, idiomatic test examples for readers.

Also applies to: 219-234, 295-320

packages/docs/src/guide/essentials/getting-started.md (1)

89-118: Clear introduction of define() with logical progression.

The guide demonstrates a natural progression from inline functions to declarative command definition with define(). The import addition and usage are consistent with other documentation files, and the example clearly shows the benefits of declarative configuration. This is a pedagogically sound introduction to the API.

packages/docs/src/guide/plugin/guidelines.md (1)

839-847: README template correctly demonstrates define() usage.

The provided README template is a helpful reference for plugin authors. It correctly shows the updated API pattern with define() wrapper and serves as a clear guide for documentation authoring. The imports and usage are consistent with updated guidelines across the documentation.

packages/docs/src/guide/advanced/command-hooks.md (1)

55-80: define() integrates correctly with lifecycle hooks.

The examples demonstrate proper integration of define() with CLI lifecycle hooks (onBeforeCommand, onAfterCommand, onErrorCommand). The pattern correctly separates command definition from CLI configuration, with hooks remaining in the options object. The usage is consistent and clear.

packages/docs/src/guide/advanced/internationalization.md (1)

156-178: define() correctly shown alongside i18n helper functions.

The examples demonstrate proper usage of define() for basic commands and showcase how specialized i18n helpers like defineI18nWithTypes extend the base define() functionality. The pattern is clear and provides good context for understanding the API hierarchy.

packages/docs/src/guide/essentials/declarative.md (3)

16-35: Declarative structure clearly presented with define().

The guide provides an excellent introduction to the command structure with clear comments explaining each section. The define() wrapper is presented naturally as the primary way to create commands, making it the idiomatic pattern for new users.


47-110: Complete example demonstrates full declarative capabilities.

The comprehensive example shows how define() brings together metadata, arguments, examples, and execution logic in an organized structure. The progression through different configuration options is pedagogically sound and provides excellent guidance for users building CLIs of increasing complexity.


183-340: Advanced features (positional args, custom types, options) correctly demonstrated.

All advanced examples—positional arguments, custom type parsing, kebab-case conversion, negatable options, and conflicting options—consistently use define() and maintain proper patterns. The examples effectively teach both syntax and best practices.

const command = define({ name: 'deploy', description: 'Deploy', run: vi.fn() })
const ctx = await createCommandContext({ command })
const extension = await plugin.extension.factory(ctx, command)
await plugin.extension.onFactory?.(ctx, command)

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.

⚠️ Potential issue | 🔴 Critical

Fix incorrect API call in test example.

Line 471 calls plugin.extension.onFactory?.(), but based on the plugin structure defined in this guide, onExtension is a top-level callback on the plugin object, not a property of plugin.extension. The correct call should be plugin.onExtension?.().

- await plugin.extension.onFactory?.(ctx, command)
+ await plugin.onExtension?.(ctx, command)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await plugin.extension.onFactory?.(ctx, command)
await plugin.onExtension?.(ctx, command)
🤖 Prompt for AI Agents
In packages/docs/src/guide/plugin/testing.md around line 471, the example
incorrectly calls plugin.extension.onFactory?.(ctx, command); change this to
call the top-level callback plugin.onExtension?.(ctx, command) instead (pass the
same ctx and command arguments) so the example matches the plugin structure
described in the guide.

@kazupon kazupon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks a lot!
LGTM!

@kazupon
kazupon merged commit e79130e into kazupon:main Dec 10, 2025
9 checks passed
@kazupon kazupon added the documentation Includes documetation fixes label Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Includes documetation fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants