dcli
  • Introduction
  • What does DCli do?
  • Install DCli
    • Installing on Windows
  • Writing your first CLI app
  • Add DCli to your project
  • pub.dev
  • github
  • Dart basics
    • Dart lambda functions
    • Function Arguments
    • Futures
    • stdin/stdout/stderr a primer
  • Tour
    • Overview
    • Using DCli functions
    • User input
      • Ask Validators
    • Displaying information
    • Managing Files And Directories
    • Environment variables
    • Calling apps
    • Redirecting output
    • Command Line Arguments
    • Paths
    • Glob Expansion
    • Piping
    • Locking
    • Fetch
    • The evils of CD
    • Assets/Resources
    • Cross Platform
      • Posix
      • Windows
      • Docker
        • Detecting Docker
        • Add DCli to a Docker Container
        • Example DCli app in Docker
  • Elevated Privileges
    • Sudo
  • Performance
  • Dependency Management
    • Dependency Management
    • Pubspec Managment
  • DCli Tools
    • DCli tools
    • Use a shebang #!
    • DCli Compile
    • DCli Clean
    • DCli Create
    • DCli Doctor
    • DCli Install
    • DCli Run
    • DCli Warmup
    • DCli Pack
    • Upgrade DCli
  • Internal Workings
    • Internal Workings
    • waitForEx
  • Contributing
    • Creating a release
    • Running Unit tests
    • Implemention support for a shell
    • Templates
  • References
  • Examples
    • Projects
    • Code
      • hello world.
      • dcompress
      • dpath
      • dmysql
      • dshell
      • dwhich
      • dipaddr
      • gnome launcher
  • Articles
    • build CLI apps in dart - part 1
    • build CLI apps in dart - part 2
    • Dealing with permissions
    • 3rd Party console packages
  • Dart on Linux - the perfect CLI tooling
  • Improving your build environment
    • Existing tooling
    • Building with Dart
    • A home for your build tools
  • Olivier Revial - CLI apps made easy
  • Video: package of the week
Powered by GitBook
On this page
  • Adding support for a shell
  • Basic Shell support
  • Privileged User
  • Install support
  • Completion Support

Was this helpful?

  1. Contributing

Implemention support for a shell

DCli provide access to an abstracted interface to a shell's underlying functions through the Shell class.

DCli provides various levels of support for a number of shells including:

  • ash

  • bash

  • cmd

  • dash

  • fish

  • power shell

  • sh

  • zsh

Adding support for a shell

Adding basic support for a shell is fairly easy:

1) copy an existing shell implementation from lib/src/shell

2) modify the implementation to match your shell's implementation details

3) register your shell with by adding it to the 'shells' array in lib/src/shell/shell_detection.dart

Basic Shell support

To implement the minimal level of shell support you will need to provide implementations for:

  • Constructor 'withPid

  • name

  • hasStartScript

  • isCompletionSupported

  • hashCode

  • operator ==

Privileged User

On linux we have the concept of sudo and on Windows an Administrator. DCli exposes these concepts as a 'privileged' user.

The Shell.isPrivilegedUser method allows DCli to determine if the current script is running under a privileged user. The libraries posix_mixin.dart, cmd_shell.dart and power_shell.dart all have separate implementations of this. You may be able to use one of these existing implementations but you may need to implement your own.

Install support

DCli attempts to automate as much of the DCli and dart installation process as possible.

Ideally your shell should support configuring DCli and dart. There are standard implementations for both of these actions that you should normally be able to use.

The platform specific implementation for Windows is in windows_mixin.dart and for Linux and MacOS in posix mixin.dart.

These mixins should work for any shell so normally your shell should just 'with' the appropriate mixin.

The one exception is support updating the paths for DCli and Dart.

The DCli installer calls Shell.addToPath in order to achieve this.

You will most likely need to implement a custom implementation of Shell.addToPath. Have a look at bashshell.dart and cmd_shell.dart for example implementations.

Completion Support

Some shells offer tab completion.

At the time of this writing DCli only supports tab completion for bash.

To implement tab completion for other shells you need to:

Override the lib/src/shell/Shell.dart methods :

  • isCompletionSupported

  • isCompletionInstalled

  • installTabCompletion

You then need to implement a tab completion system for your shell.

For bash DCli ships the executable bin/dcli_complete.

If your Shell's completion tooling allows/expects the use of an executable to provide the tab completion support you may modify the dcli_complete.dart library to also provide completion for you shell.

You can use the Shell.current method to determine if you shell is being run when the dcli_complete is executed.

PreviousRunning Unit testsNextTemplates

Last updated 2 years ago

Was this helpful?