sheller 0.3.4 copy "sheller: ^0.3.4" to clipboard
sheller: ^0.3.4 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 = shellSync("cd $outputDir && dart pub run index_generator && find . -maxdepth 1 -type f");

Table of Contents #

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

Examples #

// int async
int number = await shell("echo 1");
assert(number == 1);
// json
String data = '{"id":1, "name":"lorem ipsum", "address":"dolor set amet"}';
Map<String, dynamic> json = shellSync('echo $data');
assert(json.entries.length == 3);
// List<double>
List<double> doubleList = shellSync('echo 1 2 3');
assert(doubleList.length == 3);
// Class version
ShellSync shellClass = ShellSync("echo 1");
int id = shellClass.rawResult.pid; // shell.rawResult.runtimeType == ProcessResult
String stringResult = shellClass.stringResult; // == "1"
int convertedResult = shellClass(); // == 1

Valid Conversion Types #

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

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;
  validate(() => 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(shellSync(command));

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

  final generateBarrelFileCommand = "cd $outputDir && dart pub run index_generator";
  print(shellSync(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