dcli_core library

Classes

Cat
Class for the cat function.
DCliFunction
Base class for the classes that implement the public DCli functions.
DCliPlatform
DCliPlatform exists so we can scope Platform in unit tests to return non-standard results e.g. isWindows == true on a linux platform
Env
Sets gets an environment variable for the current process.
Find
Implementation for the _find function.
FindItem
Holds details of a file system entity returned by the find function.
LimitedStreamController<T>
A specialized StreamController that limits the no. of elements that can be in the stream.
LineFile
Provide s collection of methods to make it easy to read/write a file line by line.
Settings
StackList<T>
A classic Stack of items with a push and pop method.
Which
Returned from the which funtion to provide the details we discovered about appname.
WhichSearch
Search resutls from the which method.

Extensions

PlatformEx on Platform
Extensions for the Platform class

Properties

env Env
Provides access to shell environment variables.
no setter
envs Map<String, String>
Returns a map of all the environment variables inherited from the parent as well as any changes made by calls to env[]=.
no setter
eol String
no setter
HOME String
returns the path to the OS specific HOME directory
no setter
PATH List<String>
Returns the list of directory paths that are contained in the OS's PATH environment variable. They are returned in the same order that they appear within the PATH environment variable (as order is important.)
no setter
pwd String
Returns the current working directory.
no setter
rootPath String
Returns the root path of your file system.
no setter

Functions

backupFile(String pathToFile, {bool ignoreMissing = false}) → void
Provide a very simple mechanism to backup a single file.
calculateHash(String path) → Digest
cat(String path, {LineAction stdout = print}) → void
Prints the contents of the file located at path to stdout.
copy(String from, String to, {bool overwrite = false}) → void
Copies the file from to the path to.
copyTree(String from, String to, {bool overwrite = false, bool includeHidden = false, bool recursive = true, bool filter(String file) = _allowAll}) → void
Copies the contents of the from directory to the to path with an optional filter.
createDir(String path, {bool recursive = false}) String
Creates a directory as described by path. Path may be a single path segment (e.g. bin) or a full or partial tree (e.g. /usr/bin)
createTempDir() String
Creates a temporary directory under the system temp folder.
createTempFile({String? suffix}) String
Generates a temporary filename in the system temp directory that is guaranteed to be unique.
createTempFilename({String? suffix, String? pathToTempDir}) String
Generates a temporary filename in pathToTempDir or if inTempDir os not passed then in the system temp directory. The generated filename is is guaranteed to be globally unique.
delete(String path) → void
Deletes the file at path.
deleteDir(String path, {bool recursive = true}) → void
Deletes the directory located at path.
Deletes the symlink at linkPath
devNull(String? line) → void
devNull is a convenience function which you can use if you want to ignore the output of a LineAction. Its typical useage is a forEach where you don't want to see any stdout but you still want to see errors printed to stderr.
exists(String path, {bool followLinks = true}) bool
Returns true if the given path exists. It may be a file, directory or link.
fileLength(String pathToFile) int
Returns the length of the file at pathToFile in bytes.
find(String pattern, {required ProgressCallback progress, bool caseSensitive = false, bool recursive = true, bool includeHidden = false, String workingDirectory = '.', List<FileSystemEntityType> types = const [Find.file]}) → void
Returns the list of files in the current and child directories that match the passed glob pattern.
Returns count lines from the file at path.
isDirectory(String path) bool
Returns true if the given path is a directory.
isEmpty(String pathToDirectory) bool
Returns true if the passed pathToDirectory is an empty directory. For large directories this operation can be expensive.
isFile(String path) bool
Returns true if the given path points to a file.
Returns true if the given path is a symlink
isOnPATH(String path) bool
Tests if the given path is contained in the OS's PATH environment variable. An canonicalized match of path is made against each path on the OS's path.
lastModified(String path) DateTime
Returns the datetime the path was last modified
move(String from, String to, {bool overwrite = false}) → void
Moves the file from to the location to.
moveDir(String from, String to) → void
Moves or renames the from directory to the to the to path.
moveTree(String from, String to, {bool overwrite = false, bool includeHidden = false, bool filter(String file) = _allowAll}) → void
Recursively moves the contents of the from directory to the to the to path with an optional filter.
privatePath(String part1, [String? part2, String? part3, String? part4, String? part5, String? part6, String? part7]) String
Removes the users home directory from a path replacing it with ~
Resolves the a symbolic link pathToLink to the ultimate target path.
restoreFile(String pathToFile, {bool ignoreMissing = false}) → void
Designed to work with backupFile to restore a file from backup. The existing file is deleted and restored from the .bak/
setLastModifed(String path, DateTime lastModified) → void
Sets the last modified datetime on the given the path.
stat(String path) FileStat
Returns a FileStat instance describing the file or directory located by path.
Creates a link at linkPath which points to an existing file or directory at existingPath
tail(String path, int lines) List<String>
Returns count lines from the end of the file at path.
touch(String path, {bool create = false}) String
Updates the last modified time stamp of a file.
truepath(String part1, [String? part2, String? part3, String? part4, String? part5, String? part6, String? part7]) String
truepath creates an absolute and normalized path.
verbose(String callback()) → void
If Settings.isVerbose is true then this method will call callback to get a String which will be logged to the console or the log file set via the verbose command line option.
which(String appname, {bool first = true, bool verbose = false, bool extensionSearch = true, void progress(WhichSearch)?}) Which
Searches the PATH for the location of the application give by appname.
withEnvironment<R>(R callback(), {required Map<String, String> environment}) → R
Injects environment variables into the scope of the callback method. You must withEnvironmentAsync if the callback is async.
withEnvironmentAsync<R>(Future<R> callback(), {required Map<String, String> environment}) Future<R>
Injects environment variables into the scope of the callback method.
withFileProtectionAsync<R>(List<String> protected, Future<R> action(), {String? workingDirectory}) Future<R>
EXPERIMENTAL - use with caution and the api may change.
withOpenFile<R>(String pathToFile, R action(RandomAccessFile), {FileMode fileMode = FileMode.writeOnlyAppend}) Future<R>
Opens a File and calls action passing in the open file. When action completes the file is closed. Use this method in preference to directly callling FileSync()
withOpenLineFile<R>(String pathToFile, R action(LineFile), {FileMode fileMode = FileMode.writeOnlyAppend}) → R
Opens a File and calls action passing in the open LineFile. When action completes the file is closed. Use this method in preference to directly callling FileSync()
withTempDirAsync<R>(Future<R> action(String tempDir), {bool keep = false, String? pathToTempDir}) Future<R>
Creates a temp directory and then calls action. Once action completes the temporary directory will be deleted.
withTempFileAsync<R>(Future<R> action(String tempFile), {String? suffix, String? pathToTempDir, bool create = true, bool keep = false}) Future<R>
Creates a temp file and then calls action.

Typedefs

CancelableLineAction = bool Function(String line)
Typedef for cancellable LineActions.
LineAction = void Function(String line)
Typedef for LineActions
ProgressCallback = bool Function(FindItem item)
TODO: restore after 2.16 is released.

Exceptions / Errors

BackupFileException
Thrown by the backupFile function when the file to be backed up is missing.
CatException
Thrown if the cat function encouters an error.
CopyException
Throw when the copy function encounters an error.
CopyTreeException
Throw when the copy function encounters an error.
CreateDirException
Thrown when the function createDir encounters an error
DCliException
Base class for all DCli exceptions.
DCliFunctionException
Base class for all dcli function exceptions.
DeleteDirException
Throw when deleteDir function encounters an error
DeleteException
Thrown when the delete function encounters an error
FileNotFoundException
Thrown when a file doesn't exist
FindException
Thrown when the find function encouters an error.
HeadException
Thrown if the head function encounters an error.
MoveDirException
Thrown when the moveDir function encouters an error.
MoveException
Thrown when the move function encouters an error.
MoveTreeException
Thrown when the moveTree function encouters an error.
NotAFileException
Thrown when a path is not a file.
RestoreFileException
Thrown by the restoreFile function when the backup file is missing.
RunException
Thrown when any of the process related method such as .run and .start fail.
TailException
thrown when the tail function encounters an exception
TouchException
thrown when the touch function encounters an exception