pack

package module
v0.0.0-...-39d99f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2019 License: MIT Imports: 7 Imported by: 0

README

pack

Repository moved to codeberg.org

import "git.fractalqb.de/fractalqb/pack"


Intro

For Go packages it is common and good style to have packages installabel with a simple go get... command. This is supported in a great way by having so many good tools being part of the Go distribution. However sometimes applications might require to be distributed as a binary package with a crafted distribution file-tree – especially when users are not expected to compile the application themselves.

To have a portable way to pack such a distribution one would need a portable runtime for the program that does the packing. So why not write the packing program in Go? Most of the batteries are already included in Go but IMHO they could use a little polishing, i.e. lifting the API abstraction, to make the packing code even more simple. And exactly that's what this package is provided for!

By the way…

There is just a little tool included to create a source file with constants defining the current version of the package. The idea is extraordinary simple: Write down the version parameters in a separate text file, e.g. VERSION, from which not only the Go code can be generated but that also can likely be processed by a lot of other programs too, e.g. shell, makefiles, Python and many others:

major=0
minor=2
bugfix=0
quality="a"

With such a simple file and one go generate directive, e.g. in an application's main.go

package main
…
//go:generate versioner ./VERSION ./version.go
…

a simple go generate will create the file version.go from the file VERSION:

package main

const (
	Major = 0
	Minor = 2
	Bugfix = 0
	Quality = "a"
)

and with this its trivial to let myfancyprogram show you its version like this

myfancyprogram v0.2.0a
Usage: [flags] input output
…

There are also some flags to define a common prefix for the constants, to have automatically increasing build numbers and to generate a timestamp from time.Now().

Install

To get the library for writing your packing program:

go get -u git.fractalqb.de/fractalqb/pack

To get the versioner binary:

go install -u git.fractalqb.de/fractalqb/pack/versioner

Documentation

Index

Constants

View Source
const (
	Major   = 0
	Minor   = 3
	Bugfix  = 0
	Quality = "a"
	BuildNo = 14
)

Variables

View Source
var OsDepExe = OsDepNames{
	"windows": "%s.exe",
}

Functions

func CopyFile

func CopyFile(dst, src string, osdn OsDepNames) error

CopyFile copies file with path src to file with path dst. It also tarnsfers the file mode from the src file to the dst file.

func CopyRecursive

func CopyRecursive(
	dst, src string,
	osdn OsDepNames,
	filter func(dir string, info os.FileInfo) bool,
) error

CopyRecursive copies the content of the src directory into the dst directory. If filter is not nil only those files or subdirectories are copied for which the filter returns true.

func CopyToDir

func CopyToDir(dst string, osdn OsDepNames, files ...string) error

CopyToDir copies a list of files to a single destination directory using CopyFile on each source file.

func CopyTree

func CopyTree(
	dst, src string,
	osdn OsDepNames,
	filter func(dir string, info os.FileInfo) bool,
) error

CopyTree copies the directory tree src into the dst directory, i.e. on succes the directory dst will contain one, perhaps new, directory src.

func ZipDist

func ZipDist(zipname string, dist, distDir string) error

ZipDist creates a ZIP file with filenam zipname. Extracting the package will create a folder with name dist. The contents of the distribution is taken from distDir.

Types

type OsDepNames

type OsDepNames = map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL