{% extends "docs_base.html" %}
{% block content %}
<div class="prose prose-slate max-w-none">
<h1>Commands</h1>
<p>Ruskit provides a set of CLI commands to help you scaffold and manage your application. These commands are available through the <code>cargo kit</code> command-line interface.</p>
<h2>Command Overview</h2>
<div class="overflow-x-auto">
<table class="min-w-full table-auto">
<thead>
<tr>
<th class="px-4 py-2 text-left">Command</th>
<th class="px-4 py-2 text-left">Description</th>
<th class="px-4 py-2 text-left">Example</th>
</tr>
</thead>
<tbody>
<tr class="bg-slate-100">
<td class="px-4 py-2 font-semibold" colspan="3">Database Commands</td>
</tr>
<tr>
<td class="px-4 py-2"><code>migrate</code></td>
<td class="px-4 py-2">Run all pending database migrations</td>
<td class="px-4 py-2"><code>cargo kit migrate</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>migrate:fresh</code></td>
<td class="px-4 py-2">Drop all tables and re-run all migrations</td>
<td class="px-4 py-2"><code>cargo kit migrate:fresh</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>db:seed</code></td>
<td class="px-4 py-2">Seed the database with sample data</td>
<td class="px-4 py-2"><code>cargo kit db:seed</code></td>
</tr>
<tr class="bg-slate-100">
<td class="px-4 py-2 font-semibold" colspan="3">Development Commands</td>
</tr>
<tr>
<td class="px-4 py-2"><code>dev</code></td>
<td class="px-4 py-2">Start development server with hot reload</td>
<td class="px-4 py-2"><code>cargo kit dev</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>serve</code></td>
<td class="px-4 py-2">Start production server</td>
<td class="px-4 py-2"><code>cargo kit serve</code></td>
</tr>
<tr class="bg-slate-100">
<td class="px-4 py-2 font-semibold" colspan="3">Make Commands</td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:model</code></td>
<td class="px-4 py-2">Create a new model with migration</td>
<td class="px-4 py-2"><code>cargo kit make:model User</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:migration</code></td>
<td class="px-4 py-2">Create a new migration for a model</td>
<td class="px-4 py-2"><code>cargo kit make:migration add_email --model User</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:factory</code></td>
<td class="px-4 py-2">Create a new factory for a model</td>
<td class="px-4 py-2"><code>cargo kit make:factory User</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:seeder</code></td>
<td class="px-4 py-2">Create a new database seeder</td>
<td class="px-4 py-2"><code>cargo kit make:seeder Users</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:controller</code></td>
<td class="px-4 py-2">Create a new controller</td>
<td class="px-4 py-2"><code>cargo kit make:controller User</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:dto</code></td>
<td class="px-4 py-2">Create a new DTO</td>
<td class="px-4 py-2"><code>cargo kit make:dto User</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>make:all</code></td>
<td class="px-4 py-2">Create model, DTO, and controller</td>
<td class="px-4 py-2"><code>cargo kit make:all Post</code></td>
</tr>
<tr class="bg-slate-100">
<td class="px-4 py-2 font-semibold" colspan="3">Inertia Commands</td>
</tr>
<tr>
<td class="px-4 py-2"><code>inertia:page</code></td>
<td class="px-4 py-2">Create a complete Inertia page</td>
<td class="px-4 py-2"><code>cargo kit inertia:page Dashboard</code></td>
</tr>
<tr>
<td class="px-4 py-2"><code>inertia:prop</code></td>
<td class="px-4 py-2">Create just the props type</td>
<td class="px-4 py-2"><code>cargo kit inertia:prop Settings</code></td>
</tr>
</tbody>
</table>
</div>
<h2>Available Commands</h2>
<h3>Database Commands</h3>
<ul>
<li><code>cargo kit migrate</code> - Run all pending database migrations</li>
<li><code>cargo kit migrate:fresh</code> - Drop all tables and re-run all migrations</li>
<li><code>cargo kit db:seed</code> - Seed the database with sample data</li>
</ul>
<h3>Development Commands</h3>
<ul>
<li><code>cargo kit dev</code> - Start development server with hot reload</li>
<li><code>cargo kit serve</code> - Start production server</li>
</ul>
<h3>Make Commands</h3>
<h4>Models and Database</h4>
<ul>
<li>
<code>cargo kit make:model <Name></code> - Create a new model with migration
<pre><code class="language-bash">cargo kit make:model User</code></pre>
</li>
<li>
<code>cargo kit make:migration <name> --model <ModelName></code> - Create a new migration for an existing model
<pre><code class="language-bash">cargo kit make:migration add_email_to_users --model User</code></pre>
</li>
<li>
<code>cargo kit make:factory <Name></code> - Create a new factory for a model
<pre><code class="language-bash">cargo kit make:factory User</code></pre>
</li>
<li>
<code>cargo kit make:seeder <Name></code> - Create a new database seeder
<pre><code class="language-bash">cargo kit make:seeder Users</code></pre>
</li>
</ul>
<h4>Controllers and DTOs</h4>
<ul>
<li>
<code>cargo kit make:controller <Name></code> - Create a new controller
<pre><code class="language-bash">cargo kit make:controller User</code></pre>
</li>
<li>
<code>cargo kit make:dto <Name></code> - Create a new DTO (Data Transfer Object)
<pre><code class="language-bash">cargo kit make:dto User</code></pre>
</li>
</ul>
<h4>All-in-One Scaffolding</h4>
<ul>
<li>
<code>cargo kit make:all <Name></code> - Create model, DTO, and controller in one command
<pre><code class="language-bash">cargo kit make:all Post</code></pre>
<p>This command will:</p>
<ol>
<li>Create a model with migration</li>
<li>Create DTOs for requests and responses</li>
<li>Create a controller with basic CRUD operations</li>
</ol>
</li>
</ul>
<h3>Inertia Commands</h3>
<ul>
<li>
<code>cargo kit inertia:page <Name></code> - Create a complete Inertia page
<pre><code class="language-bash">cargo kit inertia:page Dashboard</code></pre>
<p>This command will:</p>
<ol>
<li>Create a props type in <code>src/app/dtos/dashboard.rs</code></li>
<li>Create a controller in <code>src/app/controllers/dashboard_controller.rs</code></li>
<li>Create a React component in <code>resources/js/pages/Dashboard.tsx</code></li>
</ol>
</li>
<li>
<code>cargo kit inertia:prop <Name></code> - Create just the props type
<pre><code class="language-bash">cargo kit inertia:prop Settings</code></pre>
<p>Useful when:</p>
<ul>
<li>Adding props to an existing page</li>
<li>Creating shared props used by multiple components</li>
<li>Defining the contract first before implementing the UI</li>
</ul>
</li>
</ul>
<h2>Command Behavior</h2>
<h3>Model Generation</h3>
<ul>
<li>Creates a new model file in <code>src/app/models</code></li>
<li>Automatically creates a migration</li>
<li>Updates <code>mod.rs</code> to include the new model</li>
<li>Includes basic timestamp fields and ID</li>
</ul>
<h3>Controller Generation</h3>
<ul>
<li>Creates a new controller in <code>src/app/controllers</code></li>
<li>Checks for existence of related model and DTOs</li>
<li>Generates CRUD methods if model and DTOs exist</li>
<li>Updates <code>mod.rs</code> to include the new controller</li>
</ul>
<h3>DTO Generation</h3>
<ul>
<li>Creates request and response DTOs in <code>src/app/dtos</code></li>
<li>Includes validation support</li>
<li>Generates From implementations for model conversion</li>
<li>Updates <code>mod.rs</code> to include the new DTOs</li>
</ul>
<h3>Migration Generation</h3>
<ul>
<li>Creates a new migration in the model file</li>
<li>Uses timestamp-based ordering</li>
<li>Provides up and down migration templates</li>
</ul>
<h3>Factory Generation</h3>
<ul>
<li>Creates a new factory in <code>src/app/factories</code></li>
<li>Includes fake data generation setup</li>
<li>Updates <code>mod.rs</code> to include the new factory</li>
</ul>
<h3>Seeder Generation</h3>
<ul>
<li>Creates a new seeder in <code>src/app/seeders</code></li>
<li>Includes basic seeder structure</li>
<li>Updates <code>mod.rs</code> to include the new seeder</li>
</ul>
<h3>Inertia Page Generation</h3>
<ul>
<li>Creates a props type with TypeScript export</li>
<li>Creates a controller with Inertia rendering</li>
<li>Creates a React component with TypeScript types</li>
<li>Sets up all necessary imports and routing</li>
</ul>
<h2>Best Practices</h2>
<ol>
<li>
Use PascalCase for model, controller, and DTO names:
<pre><code class="language-bash">cargo kit make:model User
cargo kit make:controller BlogPost
cargo kit make:dto UserProfile</code></pre>
</li>
<li>
Use snake_case for migration names:
<pre><code class="language-bash">cargo kit make:migration add_email_to_users --model User</code></pre>
</li>
<li>
When using <code>make:all</code>, ensure the name represents a single entity:
<pre><code class="language-bash">cargo kit make:all BlogPost # Good
cargo kit make:all blog_posts # Not recommended</code></pre>
</li>
<li>
Run migrations after creating or modifying models:
<pre><code class="language-bash">cargo kit migrate</code></pre>
</li>
<li>
Use <code>migrate:fresh</code> during development to reset the database:
<pre><code class="language-bash">cargo kit migrate:fresh</code></pre>
</li>
</ol>
</div>
{% endblock %}