Stega is a comprehensive CLI framework built with Deno, featuring advanced command management, plugin support, and extensive customization options. This guide will walk you through using Stega effectively in your projects.
- Getting Started
- Core Concepts
- Command System
- Configuration
- Plugins
- Advanced Features
- Troubleshooting
Install Stega using Deno:
deno install --allow-all -n stega mod.ts
Create a new CLI application:
import { CLI, Command } from "./mod.ts";
const cli = new CLI();
// Register a simple command
const greetCommand: Command = {
name: "greet",
description: "Greet a user",
options: [
{
name: "name",
type: "string",
required: true,
description: "Name to greet"
}
],
action: (args) => {
console.log(`Hello, ${args.flags.name}!`);
}
};
cli.register(greetCommand);
// Run the CLI
await cli.run();
Commands are the basic building blocks of your CLI application. Each command has:
- A unique name
- Optional description
- Configurable options/flags
- An action to execute
- Optional subcommands
Flags modify command behavior:
const command: Command = {
name: "example",
options: [
{
name: "verbose",
alias: "v",
type: "boolean",
description: "Enable verbose output"
},
{
name: "output",
alias: "o",
type: "string",
required: true,
description: "Output file path"
}
],
action: (args) => {
// Access flags via args.flags
const verbose = args.flags.verbose;
const output = args.flags.output;
}
};
Create hierarchical command structures:
const parentCommand: Command = {
name: "parent",
subcommands: [
{
name: "child",
action: () => {
console.log("Child command executed");
}
}
],
action: () => {
console.log("Parent command executed");
}
};
Create a stega.config.json
in your project root:
{
"plugins": [
"stega-plugin-typescript",
"stega-plugin-docker"
],
"commands": {
"build": {
"target": "es2020",
"outDir": "dist"
}
},
"i18n": {
"defaultLocale": "en",
"locales": ["en", "es", "fr"]
}
}
Override configuration using environment variables:
STEGA_LOG_LEVEL=debug stega command
Load plugins in your CLI:
const cli = new CLI();
await cli.loadPlugins([
"./plugins/custom-plugin.ts"
]);
Create a plugin:
const plugin: Plugin = {
metadata: {
name: "my-plugin",
version: "1.0.0"
},
init: async (cli) => {
cli.register({
name: "custom-command",
action: () => {
console.log("Custom command executed");
}
});
}
};
export default plugin;
Add middleware for cross-cutting concerns:
cli.use(async (args, command, next) => {
console.log(`Executing command: ${command.name}`);
const start = Date.now();
await next();
console.log(`Execution time: ${Date.now() - start}ms`);
});
Use the template system:
await cli.runCommand([
"template",
"generate",
"--template=component",
"--output=src/Button.tsx",
"--variables",
JSON.stringify({
name: "Button",
props: ["label", "onClick"]
})
]);
Create automated workflows:
{
"name": "build-and-deploy",
"steps": [
{
"name": "build",
"command": "build --target=production"
},
{
"name": "test",
"command": "test --coverage"
},
{
"name": "deploy",
"command": "deploy --env=prod",
"condition": "process.env.BRANCH === 'main'"
}
]
}
-
Command Not Found
- Ensure command is registered
- Check command name spelling
- Verify plugin loading
-
Permission Errors
- Check Deno permissions
- Verify file access rights
- Review environment variables
-
Plugin Loading Failures
- Validate plugin format
- Check plugin compatibility
- Review plugin dependencies
Enable debug logging:
STEGA_LOG_LEVEL=debug stega command
Use the built-in help system:
stega help [command]
-
Command Organization
- Group related commands
- Use meaningful command names
- Provide clear descriptions
-
Error Handling
- Validate inputs
- Provide meaningful errors
- Handle edge cases
-
Performance
- Use lazy loading
- Optimize plugin loading
- Cache when appropriate
-
Security
- Validate all inputs
- Use minimum required permissions
- Follow security guidelines