pack

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 9 Imported by: 1

README

pack

Test Coverage Go Report Card GoDoc

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
patch=3
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
	Patch = 3
	Quality = `a`
)

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

myfancyprogram v0.2.3-a
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(). Since version 0.4.0 versioner checks some convetions for semantic versioning by default:

  • Are major, minor and patch defined as valid version numbers

  • Do other values comply with SemVer character set, i.e. [0-9a-zA-Z-]

For backward compatibility this can be switched off.

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

Dependencies

Dependency Graph

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func CollectToDir

func CollectToDir(
	dst, root string,
	filter func(dir string, file os.FileInfo) bool,
	osdn OsDepNames,
) error

Search file tree root for files that match filter and copy them to the single destination directory dst. If filter is nil all files are collected.

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,
	filter func(dir string, info os.FileInfo) bool,
	osdn OsDepNames,
) 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,
	filter func(dir string, info os.FileInfo) bool,
	osdn OsDepNames,
) 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 SetLog added in v0.10.0

func SetLog(l *slog.Logger)

func Task

func Task(name string, do func() error) (err error)

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