Skip to content

goradd/gofile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

gofile

gofile is a go module aware file and directory manipulation tool primarily useful for building go applications and libraries.

Any directory can be represented as a module name, followed by a subdirectory and the real path of the module will be substituted for the module name. Path names should use forward slashes to separate directories, and you can substitute environment variables into the path names using $VAR, or ${VAR} syntax.

gofile is particularly useful for making build scripts for cross-platform projects. The cross-platform feature allows you to create command-line scripts that will work on Windows and Unix based systems. The module aware feature allows you to specify a path relative to a module's location, simply by starting the path with the module specifier.

If you put "replace" statements in the go.mod file, gofile will honor those too. For example, if your go.mod file has the following replace statement:

replace github.com/myproj/proj => /proj-src

and you execute the following command from within the source tree of the go.mod file:

gofile copy github.com/myproj/proj/README.md /a/b/

gofile will copy the README.md file from /proj-src to the /a/b/ directory.

gofile exports the ModulePaths() function as a library so you can build your own module aware tools.

When specifying files using glob patterns (i.e *.txt), surround the file specifier with quotes so that gofile will process the pattern rather than the operating system.

gofile remove "github.com/myproj/proj/*.tmp"

Installation

go install github.com/goradd/gofile@latest

Usage

gofile <command> <args...> [options] 

Commands

With most of the following commands, -v will output status information while gofile is running.

-x specifies what to exclude when expanding a path that uses * or ? expansions. Note that the * pattern does not match the path separator, so it only expands one level deep. The exclude pattern can include wild cards like * and ?, but it will only compare against the last item in a path. For example, if you have the following directories in the /tmp directory:

  • test1
  • test2

Then specifying -x test2 /tmp/* will result in only /tmp/test1 being used.

-o will force

Help

gofile -h

will print a complete description of the options and arguments of gofile.

Path

Outputs the absolute path of a go module aware path. If the module is not found, it outputs the path unchanged.

Usage:

gofile path <src> 

Copy

Copies a file or directory to another file or directory.

Usage:

gofile copy [-x excludes...] [-o|-n] <src> <dest> 

-x specifies names of files or directories you want to exclude from the source. This will match file patterns as well. This is useful when copying whole directories but needing to exclude specific types of files from the process.

Normally, a previously existing file will not be overwritten, and a previously existing directory will not be deleted first but rather files will be added that are not present in the directory. The -o option will force an overwrite of previously existing files, and the -n option will overwrite only if the new file is newer than the old one. If you want to replace a previously existing directory, use the remove command described below first.

Generate

Runs go generate on the given file.

Usage:

gofile generate [-x excludes...] <sources...>

-x specifies names of files or directories you want to exclude from the source. This is useful when expanding a directory using '*'.

Mkdir

Creates the named directory if it does not exist. Sets it to be writable.

Usage:

gofile mkdir <dest>

Remove

Deletes the named directories or files.

Usage:

gofile remove [-x excludes...] <dest...> 

-x specifies names of files or directories you want to exclude from the destination. This is useful when expanding a directory using '*'.

GZip

Compresses the given files using the GZip method.

If a directory is specified, then the files inside that directory are individually compressed. This will recursively do the same to directories within the specified directory.

Compressed files are placed in the same directory as the source file, and the file name is appended with ".gz". If a file already has a ".gz" extension, gofile will assume the file is already compressed and skip it.

Usage:

gofile gzip [-d] [-q level] [-x excludes...] <dest...> 

-x specifies names of files or directories you want to exclude from compression. For exmaple, "-x *.txt" will prevent all files ending in ".txt" from being compressed. Specifying the name of a directory will exclude all the files within that directory.

-d will delete the source file after being compressed. Excluded files specified in the -x option are not removed.

-q specifies the compression level. Default is 9, which is the maximum.

Brotli

Compresses the given files using the Brotli method.

If a directory is specified, then the files inside that directory are individually compressed. This will recursively do the same to directories within the specified directory.

Compressed files are placed in the same directory as the source file, and the file name is appended with ".br". If a file already has a ".br" extension, gofile will assume the file is already compressed and skip it.

Usage:

gofile brotli [-d] [-q level] [-x excludes...] <dest...> 

-x specifies names of files or directories you want to exclude from compression. For exmaple, "-x *.txt" will prevent all files ending in ".txt" from being compressed. Specifying the name of a directory will exclude all the files within that directory.

-d will delete the source file after being compressed. Excluded files specified in the -x option are not removed.

-q specifies the compression level. Default is 11, which is the maximum.