Skip to content

nicomt/dart-shlex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dart-shlex

dart-shlex is a Dart module for quoting and parsing shell commands. This library is a port of the node-shelex traying to keep as close to the original as possible.

The following is verbatim quote from the original documentation.

The API was inspired by the shlex module from the Python Standard Library. However, the Python implementation is fairly complex, and supports a confusing matrix of modes that is not replicated here. node-shlex always operates in what the Python module calls "POSIX mode."

As of version 2.0.0, Bash's ANSI C strings ($'x') and locale-specific translation strings ($"x") are supported. This diverges from the Python shlex behavior but makes parsing more accurate.

Note that node-shlex does not attempt to split on or otherwise parse operators (such as 2>/dev/null), and it does not perform variable interpolation.

Usage

shlex.quote()

import 'package:shlex/shlex.dart' as shlex;

main() {
  shlex.quote("abc");      // returns: abc
  shlex.quote("abc def");  // returns: 'abc def'
  shlex.quote("can't");    // returns: 'can'"'"'t'
}

shlex.split()

import 'package:shlex/shlex.dart' as shlex;

main() {
  shlex.split('ls -al /')  // returns: [ 'ls', '-al', '/' ]
  shlex.split('rm -f "/Volumes/Macintosh HD"')  // returns [ 'rm', '-f', '/Volumes/Macintosh HD' ]
}

About

Dart module for quoting and parsing shell commands.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages