搜索插件、代码仓与 APP 分类

cli_completion 封面
插件详情v0.6.0

cli_completion

为使用 CommandRunner 构建的 Dart 命令行界面提供完成功能。由 Very Good Ventures 开发。

AndroidiOSmacOSWindowsLinux
近 30 天下载
97万
喜欢数
71
Pub 分数
150

安装插件

flutter pub add cli_completion

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter/Dart 包,为使用 CommandRunner 构建的命令行界面添加自动补全支持。由 Very Good Ventures 设计,该包可让开发者通过提供对命令、标志和参数的智能建议来提升 CLI 的可用性。该包可与现有的基于 CommandRunner 的工具无缝集成,支持 Android、iOS、macOS、Windows 和 Linux 等主要平台。它通过极少的设置即可简化交互式、用户友好的命令行应用程序的开发。

适合场景

  • 增强CLI工具的易用性
  • 为命令行应用程序添加标签完成
  • 改进终端工作流中的开发人员体验
  • 构建交互式 Dart 命令行工具
  • 支持复杂的参数解析并提供建议

主要特点

  • 与 CommandRunner 的无缝集成
  • 平台无关的补全支持
  • 所需配置最少
  • 实时标签补全
  • 可扩展以支持自定义补全

适合对象

  • Dart CLI 开发人员
  • 需要交互式终端输入的工具
  • 开源命令行项目
  • 基于 CommandRunner 的应用程序
  • 注重CLI设计中用户体验的团队

使用建议

  • 需要 CommandRunner 作为依赖项
  • 仅限基于 Dart 的 CLI 工具
  • 可能需要平台特定的设置才能完全发挥功能
  • 不适用于非CLI用例

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

CLI Completion

Very Good Ventures Very Good Ventures

ci coverage pub package style: very good analysis License: MIT


screen

Completion functionality for Dart Command-Line Interfaces built using CommandRunner.

Developed with 💙 by Very Good Ventures 🦄

Installation 💻

❗ In order to start using CLI Completion you must have the Dart SDK installed on your machine.

flutter pub add cli_completion

Usage ✨

On your CommandRunner class, extend CompletionCommandRunner :

import 'package:cli_completion/cli_completion.dart';

class ExampleCommandRunner extends CompletionCommandRunner<int> {
...

This will make the first command run to install the completion files automatically. To disable that behavior, set enableAutoInstall to false:

class ExampleCommandRunner extends CompletionCommandRunner<int> {
  
  @override
  bool get enableAutoInstall => false;
...

When enableAutoInstall is set to false, users will have to call install-completion-files to install these files manually.

$ example_cli install-completion-files

Additionally, when enableAutoInstall is disabled a completion-script command is exposed. It prints the completion script for the current shell to stdout, so users can install it wherever they prefer:

$ example_cli completion-script >> ~/.zshrc

Documentation 📝

For an overview of how this package works, check out the documentation.


Troubleshooting 🧠🔨

Tab completion is taking too long

Handling completion requests should be straightforward.

If there are any checks (like analytics, telemetry, or anything that you may have on run or runCommand overrides) before running subcommands, make sure you fast track the completion command to skip all of the unnecessary computations.

Example:

@override
Future<int?> runCommand(ArgResults topLevelResults) async {
  if (topLevelResults.command?.name == 'completion') {
    super.runCommand(topLevelResults);
      return;
  }
  // ... analytics and other unrelated stuff 
Tab completion is not working on my zsh terminal

If you are not using any zsh framework such as Oh My Zsh, you have to start the completion system manually.

Add the following lines to your ~/.zshrc file:

# Add this to the start of your zsh starter file (~/.zshrc)
autoload -Uz compinit
compinit

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目