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
Stackframe
A single frame from a stack trace.
Holds the sourceFile name and line no.
StackList <T >
A classic Stack of items with a push and pop method.
StackTraceImpl
Provides dart stack frame handling.
Which
Returned from the which funtion to provide the details we discovered
about appname.
WhichSearch
Search resutls from the which method.
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
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 })
→ Future <void >
Provide a very simple mechanism to backup a single file.
calculateHash (String path )
→ Future <Digest >
Calculates the sha256 hash of a file's
content.
cat (String path , {LineAction stdout = print })
→ Future <void >
Prints the contents of the file located at path
to stdout.
copy (String from , String to , {bool overwrite = false })
→ Future <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 })
→ Future <void >
Copies the contents of the from
directory to the
to
path with an optional filter.
createDir (String path , {bool recursive = false })
→ Future <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 ()
→ Future <String >
Creates a temporary directory under the system temp folder.
createTempFile ({String ? suffix })
→ Future <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 )
→ Future <void >
Deletes the file at path
.
deleteDir (String path , {bool recursive = true })
→ Future <void >
Deletes the directory located at path
.
deleteSymlink (String linkPath )
→ Future <void >
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 )
→ Future <int >
Returns the length of the file at pathToFile
in bytes.
find (String pattern , {required LimitedStreamController <FindItem > progress , bool caseSensitive = false , bool recursive = true , bool includeHidden = false , String workingDirectory = '.' , List <FileSystemEntityType > types = const [Find.file] })
→ Future <void >
TODO: restore after 2.16 is released.
head (String path , int lines )
→ Future <Stream <String > >
Returns count lines
from the file at path
.
isDirectory (String path )
→ bool
Returns true if the given path
is a directory.
isEmpty (String pathToDirectory )
→ Future <bool >
Returns true if the passed pathToDirectory
is an
empty directory.
For large directories this operation can be expensive.
isExcludedSource (Stackframe frame )
→ bool
isFile (String path )
→ bool
Returns true if the given path
points to a file.
isLink (String path )
→ bool
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 })
→ Future <void >
Moves the file from
to the location to
.
moveDir (String from , String to )
→ Future <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 })
→ Future <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 ~
resolveSymLink (String pathToLink )
→ Future <String >
Resolves the a symbolic link pathToLink
to the ultimate target path.
restoreFile (String pathToFile , {bool ignoreMissing = false })
→ Future <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 )
→ Future <FileStat >
Returns a FileStat instance describing the
file or directory located by path
.
symlink (String existingPath , String linkPath )
→ Future <void >
Creates a link at linkPath
which points to an
existing file or directory at existingPath
tail (String path , int lines )
→ Stream <String >
Returns count lines
from the end of the file at path
.
touch (String path , {bool create = false })
→ Future <String >
Updates the last modified time stamp of a file.
translateAbsolutePath (String absolutePath , {String ? workingDirectory , Context? context })
→ String
Windows, an absolute path starts with \\
, or a drive letter followed by
:/
or :\
.
This method will strip the prefix so the path start with a \ or /
and the prepend the drive letter so that it becomes a valid
path. If the absolutePath
doesn't contain a drive letter
then we take the drive letter from the workingDirectory
.
If this is a linux absolute path it is returned unchanged.
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 , Sink <WhichSearch > ? progress })
→ Future <Which >
Searches the PATH for the location of the application
give by appname
.
withEnvironment <R > (Future <R > callback (), {required Map <String , String > environment })
→ Future <R >
Creates a environment that is contained to the scope
of the callback
method.
withFileProtection <R > (List <String > protected , 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 , Future <R > action (LineFile ), {FileMode fileMode = FileMode.writeOnlyAppend })
→ Future <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()
withTempDir <R > (FutureOr <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.
withTempFile <R > (FutureOr <R > action (String tempFile ), {String ? suffix , String ? pathToTempDir , bool create = true , bool keep = false })
→ Future <R >
Creates a temp file and then calls action
.