executableArgumentsToString function Null safety

String executableArgumentsToString(
  1. String? executable,
  2. List<String>? arguments
)

Convenient way to display a command

Implementation

String executableArgumentsToString(
    String? executable, List<String>? arguments) {
  final sb = StringBuffer();
  if (Platform.isWindows && (basename(executable!) == executable)) {
    var ext = extension(executable);
    switch (ext) {
      case '.exe':
      case '.bat':
      case '.cmd':
      case '.com':
        executable = executable.substring(0, executable.length - 4);
    }
  }
  sb.write(executable);
  if (arguments is List && arguments!.isNotEmpty) {
    sb.write(' ${argumentsToString(arguments)}');
  }
  return sb.toString();
}