prompt 0.1.7

  • README.md
  • Installing
  • Versions
  • 11

prompt pub package Build Status

Command-line prompting that is easy to data-drive, customize, and test.

  • Question - An information request to the user.
  • Prompt - ask (or askSync) a Question with customizable UX.
  • Top-level ask and askSync - Conveniences for using the default prompt.
  • MockPrompt - A mock prompt for testing purposes.

Barista Example

##Install

pub global activate den
den install prompt

...or the manual way.

##Usage

import 'package:prompt/prompt.dart';

main() async {
  // Synchronously get a String from the user:
  var name = askSync('Name');

  // Asynchronously:
  var asyncName = await ask('Name');

  // Use [Question]s for more control:
  
  // Get a secret value:
  String password = askSync(new Question('Password', secret: true));

  // Get a boolean:
  bool likeCats = askSync(new Question.confirm('Like cats'));

  // Get an answer from a list of choices.
  String favoriteColor = askSync(new Question('Favorite color', allowed:
      ['red', 'green', 'blue']));

  // Get an `int` (custom validation):
  int favoriteNumber = askSync(new Question('Favorite number',
      parser: int.parse));

  // Make a function with prompting logic testable by passing it a prompt.
  // [prompt] is the default prompt.
  var sum = add3(prompt);

  // If you use [ask] anywhere, you must close stdin when done.
  close();
}

num add3(Prompt prompt) {
  var confident = prompt.askSync(Add3Questions.confident);
  if (!confident) {
    print('No sum for you!');
    return null;
  }
  num getNum() => prompt.askSync(Add3Questions.addend);
  return getNum() + getNum() + getNum();
}

class Add3Questions {
  static final confident = new Question.confirm('Do you think this will work');
  static final addend = new Question('Enter a number', parser: num.parse);
}

###Testing

import 'package:mock/mock.dart';
import 'package:prompt/testing.dart';
import 'package:unittest/unittest.dart';

import 'basic.dart';

main() {
  group('add3', () {
    test('should not allow doubters to ask any furthers questions', () {
      var mockPrompt = new MockPrompt((question) {
        if (question == Add3Questions.confident) return false;
        if (question == Add3Questions.addend) throw 'Asked doubter for addends';
        throw 'Unrecognized question';
      });

      var sum = add3(mockPrompt);

      expect(sum, isNull);
    });

    test('should calculate sum for believers', () {
      var mockPrompt = new MockPrompt((question) {
        if (question == Add3Questions.confident) return true;
        if (question == Add3Questions.addend) return 5;
        throw 'Unrecognized question';
      });

      var sum = add3(mockPrompt);

      mockPrompt.askLogs(Add3Questions.addend).verify(happenedExactly(3));
      expect(sum, 15);
    });
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  prompt: ^0.1.7

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:prompt/prompt.dart';
  
Version Uploaded Documentation Archive
0.1.7 Feb 9, 2015 Go to the documentation of prompt 0.1.7 Download prompt 0.1.7 archive
0.1.6 Feb 9, 2015 Go to the documentation of prompt 0.1.6 Download prompt 0.1.6 archive
0.1.5 Feb 5, 2015 Go to the documentation of prompt 0.1.5 Download prompt 0.1.5 archive
0.1.4 Jan 27, 2015 Go to the documentation of prompt 0.1.4 Download prompt 0.1.4 archive
0.1.3 Jan 15, 2015 Go to the documentation of prompt 0.1.3 Download prompt 0.1.3 archive
0.1.2 Dec 4, 2014 Go to the documentation of prompt 0.1.2 Download prompt 0.1.2 archive
0.1.1 Dec 2, 2014 Go to the documentation of prompt 0.1.1 Download prompt 0.1.1 archive
0.1.0 Nov 26, 2014 Go to the documentation of prompt 0.1.0 Download prompt 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
11
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.1.0.
 
 Because prompt depends on supports_color >=0.1.1 which requires SDK version <2.0.0, version solving failed.

Health suggestions

Format lib/prompt.dart.

Run dartfmt to format lib/prompt.dart.

Format lib/src/prompt.dart.

Run dartfmt to format lib/src/prompt.dart.

Format lib/src/question.dart.

Run dartfmt to format lib/src/question.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/stdio.dart (Run dartfmt to format lib/src/stdio.dart.)
  • lib/src/theme.dart (Run dartfmt to format lib/src/theme.dart.)
  • lib/src/util.dart (Run dartfmt to format lib/src/util.dart.)
  • lib/testing.dart (Run dartfmt to format lib/testing.dart.)

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Package is too old. (-100 points)

The package was released more than two years ago.

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use prompt.dart. Packages with multiple examples should use example/readme.md.