cli_core 0.0.2-dev.4
cli_core: ^0.0.2-dev.4 copied to clipboard
A shared utility package for CLI operations in Flutter Forge packages, providing utilities for CLI commands, Flutter project management, Melos workspace management, and file operations.
NonStop
Digital Product Development Experts for Startups & Enterprises
cli_core #
A shared utility package for CLI operations in Flutter Forge packages, providing core functionality for CLI commands, Flutter project management, and Melos workspace operations.
Table of Contents #
Overview #
CLI Core provides the foundational building blocks for creating CLI tools in the Flutter Forge ecosystem. It abstracts common CLI operations, provides progress tracking, and includes utilities for Flutter project management and Melos workspace operations.
Features #
- 🚀 Base CLI command infrastructure with progress tracking
- 📱 Flutter project creation and management utilities
- 📦 Melos workspace management utilities
- 🔧 File system utilities for common operations
Usage #
Command Infrastructure #
Create custom CLI commands by extending the base command classes:
import 'package:cli_core/cli_core.dart';
class MyCommand extends CliCommand {
@override
Future<void> run(HookContext context) async {
await trackOperation(
context,
startMessage: 'Starting operation',
endMessage: 'Operation completed',
operation: () => yourOperation(),
);
}
}
Flutter Commands #
Manage Flutter projects with built-in utilities:
class MyFlutterCommand extends BaseFlutterCommand {
Future<void> execute(HookContext context) async {
await createFlutterProject(
context: context,
name: 'my_app',
description: 'My Flutter application',
outputPath: 'path/to/output',
);
}
}
Melos Commands #
Handle Melos workspace operations:
class MyMelosCommand extends BaseMelosCommand {
Future<void> execute(HookContext context) async {
await bootstrap(
context: context,
workspacePath: 'path/to/workspace',
);
}
}
File Operations #
Perform common file system operations:
// Using file utilities
Future<void> fileOperations() async {
// Create directories
await FileUtils.ensureDirectory('path/to/dir');
// Write YAML files
await FileUtils.writeYamlFile('config.yaml', 'content: value');
// Read YAML files
final content = await FileUtils.readYamlFile('config.yaml');
// Copy files
await FileUtils.copyFile('source.txt', 'dest.txt');
// Check for mono-repo
final isMonoRepo = await FileUtils.isMonoRepo();
}
Logger Extension #
The LoggerX
extension on the Logger
class provides additional utility methods for logging in CLI applications.
Methods
void created(String message)
: Logs a message with a specific style indicating creation.void wrap(String? text, {required void Function(String?) print, int? length})
: Wraps the provided text to fit within the terminal width, taking into account ANSI escape sequences for styling.
Example
import 'package:cli_core/cli_core.dart';
import 'package:mason_logger/mason_logger.dart';
void main() {
final logger = Logger();
logger.created('Project created successfully');
logger.wrap('This is a long message that should be wrapped to fit within the terminal width.', print: print);
}
Contributing #
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Contact #
Follow us, stay up to date or reach out on:
🚀 Founded by Ajay Kumar 🎉