browser_cli 1.0.0-alpha.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 41

browser_cli

This dart package is a Command Line Interface for the web browser. Pull it into your website and create some custom processes to have all the sweet command line goodness at your fingertips!

Getting Started

Add code to html page

The following goes inside the <head>:

<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>

In the <body>, where you want the shell located, add the following:

<div id="cli-shell"></div>

Create or import processes

Any process that you want to run in the CLI needs to extend the Process class, and it needs to also have a factory that extends the ProcessFactory class.

ProcessFactory Example:

A ProcessFactory should follow the model below, providing a COMMAND, USAGE, SHORT_DESCRIPTION, and LONG_DESCRIPTION.

class EchoProcessFactory extends ProcessFactory {
  static final String COMMAND = 'echo';
  static final String USAGE = 'USAGE: echo <string>';
  static final String SHORT_DESCRIPTION =
      'Prints the supplied input back to the shell.';
  static final String LONG_DESCRIPTION =
      'Prints the supplied input back to the shell';

  EchoProcessFactory()
      : super(COMMAND, USAGE, SHORT_DESCRIPTION, LONG_DESCRIPTION);

  EchoProcess createProcess(int id, List args) =>
      new EchoProcess(id, COMMAND, args, this);
}

Process Example:

The only two required API for a Process are the constructor and the start() method. Below is a very basic Process, but they can be much more complex. Check out other Processes in the standard library for examples of different ways to parse the arguments, how to request user input within a running process, how to start other processes from within a process, and more!

class EchoProcess extends Process {
  EchoProcess(int id, String command, List args, ProcessFactory factory)
      : super(id, command, args, factory);

  Future start() async {
    if (args.isNotEmpty) {
      await output(new DivElement()..text = args.join(' '));
    } else {
      await output(new DivElement()..innerHtml = nonBreakingLineSpace);
    }
  }
}

Create a main.dart and register desired process factories

Make sure to register all the standard library process factories, as well as any custom process factories you may have.

import 'package:browser_cli/command_line_interface.dart';
import 'package:browser_cli/process_library.dart';
import 'package:my_cool_project/process_library.dart';

CommandLineInterface interface;

void main() {
  interface = new CommandLineInterface();
  _registerProcesses();
}

_registerProcesses() {
  interface.processManager.registerProcessFactories([
    new EchoProcessFactory(),
    new ExportProcessFactory(),
    new HelpProcessFactory(),
    new JobsProcessFactory(),
    new PrintEnvProcessFactory(),
    new UnsetProcessFactory(),
    // ...
  ]);
}

Style your CLI

You can use the default stylings provided with the package, or you can make your own! Below are some (but not all) of the id and class names used by browser_cli. To get a more complete list, check out the utils library.

id

  • cli-shell - The container for the CLI shell.
  • cli-standard-input - The div the user types in.
  • cli-prompt - The leading bit of text in the standard input div. Defaults to "~ user$"
  • cli-last-output - The last div output to the shell.

class

  • cli-output - This class applies to all output divs.
  • cli-stderr - This class is added to an output div when it's displaying an error message.
  • cli-input - This class applies to all (current and previous) input divs.
  • cli-visible-scroll - When you want a scrollbar in an output div.
  • cli-bordered-scroll-area - When you want the scroll area to have a border.
  • cli-hidden - When you want something to be hidden.

Changelog

0.0.1

  • Initial version, created by Stagehand

0.1.0

  • Initial upload. Framework is partially in place.

1.0.0-alpha

  • Basic command line functionality in place (minus file system).
  • Interactive IO.
  • Process management.
  • Environment variable storage and recall.
  • Command completion.
  • Input history.
  • Standard library processes thus far:
    • authentication (pseudo for now)
    • echo
    • export
    • help
    • jobs
    • printenv
    • testinput
    • unset

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  browser_cli: "^1.0.0-alpha.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:browser_cli/command_line_interface.dart';

import 'package:browser_cli/environment_variables.dart';

import 'package:browser_cli/file_manager.dart';

import 'package:browser_cli/process_library.dart';

import 'package:browser_cli/process_manager.dart';

import 'package:browser_cli/utils.dart';
        
Version Uploaded Documentation Archive
1.0.0-alpha.3 Sep 28, 2016 Go to the documentation of browser_cli 1.0.0-alpha.3 Download browser_cli 1.0.0-alpha.3 archive
1.0.0-alpha.2 Sep 28, 2016 Go to the documentation of browser_cli 1.0.0-alpha.2 Download browser_cli 1.0.0-alpha.2 archive
1.0.0-alpha.1 Sep 27, 2016 Go to the documentation of browser_cli 1.0.0-alpha.1 Download browser_cli 1.0.0-alpha.1 archive
1.0.0-alpha Sep 27, 2016 Go to the documentation of browser_cli 1.0.0-alpha Download browser_cli 1.0.0-alpha archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 14, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
57 / 100
Overall score:
Weighted score of the above. [more]
41

Platforms

Detected platforms: web

Platform components identified in package: html.

Suggestions

  • Fix lib/src/command_line_interface/key_gesture.dart.

    Strong-mode analysis of lib/src/command_line_interface/key_gesture.dart failed with the following error:

    line: 39 col: 3
    Invalid override. The type of 'KeyGesture.==' ('(KeyGesture) → bool') isn't a subtype of 'Object.==' ('(dynamic) → bool').

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Package is pre-release.

    Pre-release versions should be used with caution, their API may change in breaking ways.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use browser_cli.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.18.1 <2.0.0
browser >=0.10.0 <0.11.0 0.10.0+2
dart_to_js_script_rewriter >=1.0.1 <2.0.0 1.0.3
Transitive dependencies
args 1.3.0
async 2.0.3 2.0.4
barback 0.15.2+14
charcode 1.1.1
collection 1.14.5
csslib 0.14.1
html 0.13.2+2
logging 0.11.3+1
path 1.5.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.2
utf 0.9.0+4