### Manual Pastel Project Setup
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Manual setup steps for a Pastel CLI project, including initializing the project, installing dependencies, and configuring TypeScript.
```bash
mkdir hello-world
cd hello-world
npm init --yes
npm install pastel
npm install --save-dev typescript @sindresorhus/tsconfig
```
--------------------------------
### Run Pastel CLI Command Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Executes a Pastel CLI command with a specified option and displays the output.
```bash
hello-world --name=Jane
```
--------------------------------
### Install Pastel CLI Dependencies
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Installs the necessary packages for creating a Pastel application, including Pastel itself, Ink for UI rendering, React for component logic, and Zod for schema definition.
```bash
npm install pastel ink react zod
```
--------------------------------
### Pastel CLI Help Message Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Displays the auto-generated help message for a Pastel CLI application, showing available commands, options, and their descriptions.
```bash
hello-world --help
```
--------------------------------
### Initialize Pastel App with Custom Description
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example shows how to initialize a Pastel CLI application with a custom description using the `description` option. This overrides the description typically read from the `package.json` file.
```typescript
import Pastel from 'pastel';
const app = new Pastel({
description: 'Custom description',
});
await app.run();
```
--------------------------------
### Default Command Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Default commands are similar to index commands but have a name and appear in the help message. They are useful for creating shortcuts to frequently used commands by exporting `isDefault = true`.
```typescript
import React from 'react';
import {Text} from 'ink';
export const isDefault = true;
export default function Deploy() {
return Deploying...;
}
```
```bash
$ my-cli
```
--------------------------------
### Subcommand Structure Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Subcommands group related commands by creating nested folders within the 'commands' directory. This example shows how to group domain management commands.
```bash
commands/
deploy.tsx
login.tsx
logout.tsx
domains/
list.tsx
add.tsx
remove.tsx
```
```bash
$ my-cli domains list
$ my-cli domains add
$ my-cli domains remove
```
--------------------------------
### Initialize Pastel App with Custom Version
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example demonstrates initializing a Pastel CLI application with a custom version string using the `version` option. This version will be displayed in the help message and enable the `-v, --version` flags.
```typescript
import Pastel from 'pastel';
const app = new Pastel({
version: '1.0.0'
});
await app.run()
```
--------------------------------
### Index Command Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Index commands are files named 'index.tsx' that are executed by default when no other command is specified. This is useful for single-purpose CLIs.
```bash
commands/
index.tsx
login.tsx
logout.tsx
```
```bash
$ my-cli
```
--------------------------------
### Initialize Pastel App with Custom Name
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example demonstrates how to initialize a Pastel CLI application with a custom program name using the `name` option. This is useful when the executable name does not match the `name` field in `package.json`.
```typescript
import Pastel from 'pastel';
const app = new Pastel({
name: 'custom-cli-name',
});
await app.run();
```
--------------------------------
### Command Alias Example
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Commands can have an alias, a shorter alternative name, by exporting a variable named `alias`. This allows for quicker command execution.
```typescript
import React from 'react';
import {Text} from 'ink';
export const alias = 'i';
export default function Install() {
return Installing something...;
}
```
```bash
$ my-cli i
```
--------------------------------
### Set Default Commands and Aliases in TypeScript CLI
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Shows how to designate a command as the default action for the CLI and how to define aliases for commands. This example sets the `deploy` command as the default and also makes it accessible via the `push` alias, simplifying command invocation. Uses TypeScript.
```typescript
// source/commands/deploy.tsx
import React from 'react';
import {Text} from 'ink';
export const isDefault = true;
export const description = 'Deploy your project';
export const alias = 'push';
export default function Deploy() {
return Deploying...;
}
// Usage - all three commands do the same thing:
// $ my-cli
// Deploying...
//
// $ my-cli deploy
// Deploying...
//
// $ my-cli push
// Deploying...
```
--------------------------------
### Define Multiple Commands in Pastel
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Organizes commands within the 'commands' folder. Each file represents a command, and nested folders create subcommands. Example shows 'login' and 'logout' commands.
```tsx
import React from 'react';
import {Text} from 'ink';
export default function Login() {
return Logging in;
}
```
```tsx
import React from 'react';
import {Text} from 'ink';
export default function Logout() {
return Logging out;
}
```
--------------------------------
### Create Nested Subcommands using Folder Structure in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Explains how to organize related CLI commands into nested subcommands by structuring them within folders. This example shows a `projects` command with `create` and `list` subcommands, and hints at further nesting with `projects servers create`. It uses TypeScript and Zod for defining command options and descriptions.
```typescript
// source/commands/projects/create.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const description = 'Create a new project';
export const options = zod.object({
name: zod.string().describe('Project name'),
});
type Props = {
optons: zod.infer;
};
export default function CreateProject({options}: Props) {
return Creating project: {options.name};
}
// source/commands/projects/list.tsx
import React from 'react';
import {Text} from 'ink';
export const description = 'List all projects';
export default function ListProjects() {
return Listing projects...;
}
// Folder structure:
// commands/
// projects/
// create.tsx
// list.tsx
// servers/
// create.tsx
//
// Usage:
// $ my-cli projects create --name=my-app
// Creating project: my-app
//
// $ my-cli projects list
// Listing projects...
//
// $ my-cli projects servers create
// Creating server...
```
--------------------------------
### Command Options Definition with Zod
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Commands can define options using Zod object schemas, exported as the `options` variable. Pastel parses this schema to automatically set up options, which are passed as a prop to the command component. This example defines options for server deployment.
```typescript
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Server name'),
os: zod.enum(['Ubuntu', 'Debian']).describe('Operating system'),
memory: zod.number().describe('Memory size'),
region: zod.enum(['waw', 'lhr', 'nyc']).describe('Region'),
});
type Props = {
options: zod.infer;
};
export default function Deploy({options}: Props) {
return (
Deploying a server named "{options.name}" running {options.os} with memory
size of {options.memory} MB in {options.region} region
);
}
```
```bash
$ my-cli deploy --name=Test --os=Ubuntu --memory=1024 --region=waw
```
```bash
$ my-cli deploy --help
```
--------------------------------
### Define Array Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Illustrates defining an array option '--tag' that can be specified multiple times in Pastel CLI using Zod. The example shows how to join and display multiple string tags.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
tag: zod.array(zod.string()).describe('Tags'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Tags = {options.tags.join(', ')};
}
```
--------------------------------
### Define Enum Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Provides an example of defining an enum option '--os' with allowed values 'Ubuntu' and 'Debian' using Zod in Pastel CLI. It shows successful selection and error handling for invalid choices.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
os: zod.enum(['Ubuntu', 'Debian']).describe('Operating system'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Operating system = {options.os};
}
```
--------------------------------
### Define String Argument with Pastel and Zod
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example shows how to define a string argument named 'name' for a Pastel CLI application using Zod. The description for the argument is provided using the `argument` helper function.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.string().describe(
argument({
name: 'name',
description: 'Your name',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Hello({args}: Props) {
return Hello, {args[0]};
}
```
--------------------------------
### Define Number Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Shows how to define a number option '--age' in Pastel CLI using Zod. This example validates the input as a number and displays the provided age.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
age: zod.number().describe('Your age'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Age = {options.age};
}
```
--------------------------------
### Custom Pastel App Component
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example shows a custom `_app.tsx` component for a Pastel CLI application. This component wraps every command and can be used to share logic across all commands. It receives `Component` and `commandProps` as props and renders the command component.
```tsx
import React from 'react';
import type {AppProps} from 'pastel';
export default function App({Component, commandProps}: AppProps) {
return ;
}
```
--------------------------------
### Define Enum Argument with Pastel and Zod
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example illustrates how to define an enum argument 'os' for a Pastel CLI application using Zod. The allowed values are 'Ubuntu' and 'Debian', and the description is provided via the `argument` helper.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.enum(['Ubuntu', 'Debian']).describe(
argument({
name: 'os',
description: 'Operating system',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Example({args}: Props) {
return Operating system = {args[0]};
}
```
--------------------------------
### Define Number Argument with Pastel and Zod
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example demonstrates defining a number argument named 'age' for a Pastel CLI application using Zod. The argument's description is set using the `argument` helper.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.number().describe(
argument({
name: 'age',
description: 'Age',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Hello({args}: Props) {
return Your age is {args[0]};
}
```
--------------------------------
### Define Default True Boolean Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Demonstrates defining a boolean option '--compress' that defaults to true in Pastel CLI using Zod. This example shows how to handle negated options with the 'no-' prefix when the default is true.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
compress: zod.boolean().default(true).describe("Don't compress output"),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Compress = {String(options.compress)};
}
```
--------------------------------
### Define Boolean Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Illustrates defining a boolean option '--compress' in Pastel CLI with Zod. Boolean options default to false and cannot be required. The example shows how to display the boolean state.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
compress: zod.boolean().describe('Compress output'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Compress = {String(options.compress)};
}
```
--------------------------------
### Customize Default Value Description for Argument
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example shows how to customize the default value description for a number argument in a Pastel CLI. The `defaultValueDescription` option within the `argument` helper function is used to change how the default value '1024' is displayed in the help message.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod
.number()
.default(1024)
.describe(
argument({
name: 'number',
description: 'Some number',
defaultValueDescription: '1,204',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Example({args}: Props) {
return Some number = {args[0]};
}
```
--------------------------------
### Set Default Number Argument Value with Pastel and Zod
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
This example demonstrates how to set a default value of 1024 for a number argument named 'number' in a Pastel CLI application using Zod's `.default()` method. The default value is also reflected in the help message.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod
.number()
.default(1024)
.describe(
argument({
name: 'number',
description: 'Some number',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Example({args}: Props) {
return Some number = {args[0]};
}
```
--------------------------------
### Initialize Pastel Application
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Initializes a Pastel CLI application using import.meta for command discovery. It accepts optional configuration for the application name, version, and description, defaulting to package.json values if not provided.
```typescript
#!/usr/bin/env node
import Pastel from 'pastel';
const app = new Pastel({
importMeta: import.meta,
name: 'my-cli', // Optional: defaults to package.json name
version: '1.0.0', // Optional: defaults to package.json version
description: 'My awesome CLI tool', // Optional: defaults to package.json description
});
await app.run();
```
--------------------------------
### Create Pastel App with create-pastel-app
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Scaffolds a new Pastel CLI project with pre-configured TypeScript, linter, and tests using the create-pastel-app utility.
```bash
npm create pastel-app hello-world
hello-world
```
--------------------------------
### Optional and Required Options with Default Values
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Shows how to configure optional options with default values and descriptions. The 'build' command includes an optional environment string, a boolean flag for minification with a default of true, and a number for bundle size with a default value. This allows for flexible command execution with sensible defaults.
```typescript
// source/commands/build.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
env: zod.string().optional().describe('Environment'),
minify: zod.boolean().default(true).describe("Don't minify output"),
size:
zod
.number()
.default(1024)
.describe(
option({
description: 'Bundle size limit',
defaultValueDescription: '1 MB',
})
),
});
type Props = {
options: zod.infer;
};
export default function Build({options}: Props) {
return (
Building for {options.env ?? 'default'} env. Minify: {String(options.minify)}.
Size limit: {options.size}KB
);
}
// Usage:
// $ my-cli build
// Building for default env. Minify: true. Size limit: 1024KB
//
// $ my-cli build --env=production --no-minify --size=2048
// Building for production env. Minify: false. Size limit: 2048KB
```
--------------------------------
### Pastel CLI Entrypoint (cli.ts)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
The main entrypoint for a Pastel CLI application. It initializes the Pastel app with import metadata and runs the application.
```javascript
#!/usr/bin/env node
import Pastel from 'pastel';
const app = new Pastel({
importMeta: import.meta,
});
await app.run();
```
--------------------------------
### Define Commands with Multiple Option Types
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Illustrates defining a 'deploy' command with various option types including string, enum, number, and boolean. It uses Zod to validate these options and renders a summary of the deployment configuration. This showcases the flexibility in defining different kinds of command-line arguments.
```typescript
// source/commands/deploy.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Server name'),
os: zod.enum(['Ubuntu', 'Debian']).describe('Operating system'),
memory: zod.number().describe('Memory size in MB'),
compress: zod.boolean().describe('Enable compression'),
region: zod.enum(['waw', 'lhr', 'nyc']).describe('Region'),
});
type Props = {
options: zod.infer;
};
export default function Deploy({options}: Props) {
return (
Deploying "{options.name}" with {options.os}, {options.memory}MB RAM
in {options.region}. Compression: {String(options.compress)}
);
}
// Usage:
// $ my-cli deploy --name=prod-01 --os=Ubuntu --memory=2048 --region=waw --compress
// Deploying "prod-01" with Ubuntu, 2048MB RAM in waw. Compression: true
```
--------------------------------
### Create Simple Index Command with String Options
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Defines a basic index command for a Pastel application. It uses Zod to define a string option for a name, which is then used to render a greeting message. This demonstrates basic option definition and usage within a React component.
```typescript
// source/commands/index.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Your name'),
});
type Props = {
options: zod.infer;
};
export default function Index({options}: Props) {
return Hello, {options.name}!;
}
// Usage:
// $ my-cli --name=Jane
// Hello, Jane!
```
--------------------------------
### Create CLI Options with Aliases in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Demonstrates how to define command-line options with short aliases using Pastel and Zod. This allows users to provide options like `--force` or `-f` for the same purpose. It requires the 'pastel' and 'zod' libraries.
```typescript
// source/commands/run.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
force: zod.boolean().describe(
option({
description: 'Force execution',
alias: 'f',
}),
),
verbose: zod.boolean().describe(
option({
description: 'Verbose output',
alias: 'v',
}),
),
});
type Props = {
optons: zod.infer;
};
export default function Run({options}: Props) {
return (
Running... Force: {String(options.force)}, Verbose: {String(options.verbose)}
);
}
// Usage:
// $ my-cli run -f -v
// Running... Force: true, Verbose: true
//
// $ my-cli run --force --verbose
// Running... Force: true, Verbose: true
```
--------------------------------
### Make Pastel CLI Globally Available
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Links the locally developed Pastel CLI application to the global npm environment, making it executable from any directory.
```bash
npm link --global
```
--------------------------------
### Create Custom App Wrapper in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Wraps all commands with shared logic using a custom '_app' component. This provides consistent branding and layout across all command executions. It utilizes Ink components for terminal UI rendering.
```typescript
// source/commands/_app.tsx
import React from 'react';
import {Box, Text} from 'ink';
import type {AppProps} from 'pastel';
export default function App({Component, commandProps}: AppProps) {
return (
My CLI v1.0.0
);
}
// This wrapper will be applied to all commands in your CLI,
// providing consistent branding and layout across every command execution.
```
--------------------------------
### Handle Variable-Length Arguments in TypeScript CLI
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Illustrates how to define a command that accepts an arbitrary number of arguments, such as multiple file names for deletion. This is achieved using Zod arrays. The 'pastel' and 'zod' libraries are necessary for this implementation.
```typescript
// source/commands/remove.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const args = zod.array(zod.string()).describe('files');
type Props = {
args: zod.infer;
};
export default function Remove({args}: Props) {
return Removing: {args.join(', ')};
}
// Usage:
// $ my-cli remove file1.txt file2.txt file3.txt
// Removing: file1.txt, file2.txt, file3.txt
```
--------------------------------
### Configure Package.json for Pastel CLI Binary
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Updates the 'package.json' file to specify the compiled JavaScript file as the command-line executable for the Pastel application.
```diff
"bin": "build/cli.js"
```
--------------------------------
### Configure Argument Metadata with argument() in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Configures detailed argument metadata for documentation using the `argument()` helper function from Pastel. This function allows for defining argument names, descriptions, and default value descriptions, integrating with Zod for schema definition and validation.
```typescript
// source/commands/process.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.string().describe(
argument({
name: 'input',
description: 'Input file to process',
}),
),
zod.number().default(100).describe(
argument({
name: 'timeout',
description: 'Timeout in seconds',
defaultValueDescription: '100s',
}),
),
]);
type Props = {
args: zod.infer;
};
export default function Process({args}: Props) {
return (
Processing {args[0]} with {args[1]}s timeout
);
}
// Help output:
// $ my-cli process --help
// Usage: my-cli process [options] [timeout]
//
// Arguments:
// input Input file to process
// timeout Timeout in seconds (default: 100s)
```
--------------------------------
### Define Positional Arguments in TypeScript CLI
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Shows how to create CLI commands that accept a fixed sequence of positional arguments using Pastel's `argument` decorator with Zod tuples. This is useful for commands like file operations where the order of inputs matters. Dependencies include 'pastel' and 'zod'.
```typescript
// source/commands/move.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.string().describe(
argument({
name: 'source',
description: 'Source file path',
})
),
zod.string().describe(
argument({
name: 'target',
description: 'Target file path',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Move({args}: Props) {
return (
Moving from {args[0]} to {args[1]}
);
}
// Usage:
// $ my-cli move source.txt target.txt
// Moving from source.txt to target.txt
```
--------------------------------
### TypeScript Configuration for Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Configures TypeScript for a Pastel project, specifying the output directory for compiled JavaScript, enabling source maps, and including source files.
```json
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"outDir": "build",
"sourceMap": true
},
"include": [
"source"
]
}
```
--------------------------------
### Use Array Options for Multiple Values
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Demonstrates how to define an array option that can accept multiple values. The 'tag' command uses Zod to define an array of strings, allowing users to specify multiple tags via repeated `--tag` arguments. The output joins these tags into a comma-separated string.
```typescript
// source/commands/tag.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
tag: zod.array(zod.string()).describe(
option({
description: 'Tags to apply',
})
),
});
type Props = {
options: zod.infer;
};
export default function Tag({options}: Props) {
return Tags: {options.tag.join(', ')};
}
// Usage:
// $ my-cli tag --tag=production --tag=frontend --tag=critical
// Tags: production, frontend, critical
```
--------------------------------
### Configure Advanced Option Metadata with option() in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Configures advanced option metadata for better help messages using the `option()` helper function from Pastel. This function enhances the descriptions for CLI options, including aliases and default value descriptions. It integrates with Zod for schema definition and validation.
```typescript
// source/commands/export.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
format:
zod
.enum(['json', 'csv', 'xml'])
.describe(
option({
description: 'Export format',
valueDescription: 'format',
}),
),
output:
zod.string().default('./output.json').describe(
option({
description: 'Output file path',
alias: 'o',
defaultValueDescription: 'current directory',
}),
),
});
type Props = {
options: zod.infer;
};
export default function Export({options}: Props) {
return (
Exporting to {options.output} as {options.format}
);
}
// Help output:
// $ my-cli export --help
// Usage: my-cli export [options]
//
// Options:
// --format Export format (choices: "json", "csv", "xml")
// -o, --output Output file path (default: current directory)
// -h, --help Show help
```
--------------------------------
### Define Optional Option in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Demonstrates how to define an optional option 'os' using Zod's enum and optional() methods within a React component for a Pastel CLI application. This allows the option to be omitted, with a fallback value if not provided.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
os: zod.enum(['Ubuntu', 'Debian']).optional().describe('Operating system'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Operating system = {options.os ?? 'unspecified'};
}
```
--------------------------------
### Define Set Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Demonstrates defining a set option '--tag' in Pastel CLI using Zod. Similar to array options, but duplicate values are automatically removed, resulting in a Set instance.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
tag: zod.set(zod.string()).describe('Tags'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Tags = {[...options.tags].join(', ')};
}
```
--------------------------------
### Default Command Definition (index.tsx)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Defines the default command for a Pastel CLI application using React and Zod. It expects a 'name' option and renders a greeting.
```typescriptreact
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Your name'),
});
type Props = {
options: zod.infer;
};
export default function Index({options}: Props) {
return Hello, {options.name}!;
}
```
--------------------------------
### Define Positional Arguments in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Shows how to define two required string arguments, 'source' and 'target', using Zod's tuple type for a Pastel CLI command. The order of arguments is significant for command execution.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const args = zod.tuple([zod.string(), zod.string()]);
type Props = {
args: zod.infer;
};
export default function Move({args}: Props) {
return (
Moving from {args[0]} to {args[1]}
);
}
```
--------------------------------
### Define String Option in Pastel CLI
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Demonstrates defining a string option named '--name' using Zod in a Pastel CLI application. It requires the 'zod' library and outputs the provided name.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Your name'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Name = {options.name};
}
```
--------------------------------
### Customize Default Option Description in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Shows how to customize the default value description for an option 'size' using the `defaultValueDescription` property within Pastel's `option` helper. This provides a more user-friendly display in help messages.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
size:
zod
.number()
.default(1024)
.describe(
option({
description: 'Memory size',
defaultValueDescription: '1 GB',
}),
),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Memory = {options.size} MB;
}
```
--------------------------------
### Define Option Alias in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Demonstrates how to define an alias 'f' for a boolean option 'force' using Pastel's `option` helper. This allows the option to be triggered using either the full name or its short alias.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {option} from 'pastel';
export const options = zod.object({
force: zod.boolean().describe(
option({
description: 'Force',
alias: 'f',
}),
),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Force = {String(options.force)};
}
```
--------------------------------
### Define Array Arguments in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Illustrates how to define an argument that accepts any number of string values using Zod's array type for a Pastel CLI command. This is useful for commands like 'rm' that can operate on multiple files.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const args = zod.array(zod.string());
type Props = {
args: zod.infer;
};
export default function Remove({args}: Props) {
return Removing {args.join(', ')};
}
```
--------------------------------
### Implement Enum Validation for CLI Arguments in TypeScript
Source: https://context7.com/vadimdemedes/pastel/llms.txt
Demonstrates how to enforce specific values for a command-line argument using Zod's enum type, combined with Pastel's `argument` decorator. This ensures that only predefined options are accepted, providing clear error messages for invalid inputs. Requires 'pastel' and 'zod'.
```typescript
// source/commands/install.tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
import {argument} from 'pastel';
export const args = zod.tuple([
zod.enum(['Ubuntu', 'Debian']).describe(
argument({
name: 'os',
description: 'Operating system to install',
})
),
]);
type Props = {
args: zod.infer;
};
export default function Install({args}: Props) {
return Installing {args[0]}...;
}
// Usage:
// $ my-cli install Ubuntu
// Installing Ubuntu...
//
// $ my-cli install Windows
// error: argument 'Windows' is invalid. Allowed choices are Ubuntu, Debian.
```
--------------------------------
### Set Default Option Value in Pastel CLI (TypeScript)
Source: https://github.com/vadimdemedes/pastel/blob/main/readme.md
Illustrates how to set a default value for a numeric option 'size' using Zod's default() method in a Pastel CLI application. This ensures the option has a predefined value if not explicitly provided by the user.
```tsx
import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
size: zod.number().default(1024).describe('Memory size'),
});
type Props = {
options: zod.infer;
};
export default function Example({options}: Props) {
return Memory = {options.size} MB;
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.