sheller 0.4.0-dev2 copy "sheller: ^0.4.0-dev2" to clipboard
sheller: ^0.4.0-dev2 copied to clipboard

Ergonomic utilities for interacting with shells and converting output. Useful for writing Dart scripts.

sheller #

Pub Version Dart Package Docs License: MIT

Ergonomic utilities for interacting with shells and converting output. Useful for writing Dart scripts.


List<File> files = await $("cd $outputDir && dart pub run index_generator && find . -maxdepth 1 -type f").lines();

Table of Contents #

  1. Examples
  2. Valid Conversion Types
  3. Custom Conversion Types
  4. Real Use Case - Protobuf Package Generation Script Example

Examples #

// Linux
void main() async {
  // int
  int number = await $("echo 1")();
  assert(number == 1);
  // json
  String data ='{\\"id\\":1, \\"name\\":\\"lorem ipsum\\", \\"address\\":\\"dolor set amet\\"}';
  Map<String, dynamic> json = await $('echo $data')();
  assert(json.entries.length == 3);
  // List<double>
  List<double> doubleList = await $('echo 1 2 3').spaces();
  assert(doubleList.length == 3);
  // Class version
  $ shellClass = $("echo 1");
  int id = await shellClass.pid;
  int convertedResult = await shellClass(); // == 1
}

Valid Conversion Types #

int
double
num
BigInt
String
bool
Map<String, dynamic>
Object
FileSystemEntity
Directory
File
Link

As well as their List variants.

Custom Conversion Types #

class IntConverter extends Converter<String, int> {
  const IntConverter();

  @override
  int convert(String input) {
    int? result = int.tryParse(input);
    if (result == null) {
      throw ShellResultConversionException(int, input);
    }
    return result;
  }
}

ShellConversionConfig.add(const IntConverter());

Real Use Case - Protobuf Package Generation Script Example #

Future<void> main() async {
  String osPathSeparator = path.separator;
  assert(Directory.current.path.split(osPathSeparator).last == "lib");
  var protoFilesDir = "../../../proto";
  var outputDir = "../../generated";
  var outputSrcDir = "../../generated/lib/src";
  Directory(outputDir).deleteSync(recursive: true);
  Directory(outputSrcDir).createSync(recursive: true);

  var protoFiles = Directory(protoFilesDir)
      .listSync()
      .whereType<File>()
      .where((file) => file.path.endsWith(".proto"))
      .map((file) => file.path)
      .toList();

  var command = "protoc -I=$protoFilesDir --dart_out=grpc:$outputSrcDir ${protoFiles.join(' ')} google/protobuf/empty.proto";
  print(await $(command)());

  var toCopyOver = "../to_copy_over";
  Directory(toCopyOver).copyToSync(Directory(outputDir));

  final generateBarrelFileCommand = "cd $outputDir && dart pub run index_generator";
  print(await $(generateBarrelFileCommand)());
}
16
likes
0
pub points
43%
popularity

Publisher

verified publishervoyver.com

Ergonomic utilities for interacting with shells and converting output. Useful for writing Dart scripts.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on sheller