This commit is contained in:
Carlos Alexandro Becker
2018-01-04 10:49:15 -02:00
parent e9105fd545
commit c6a9cad760
3 changed files with 11 additions and 0 deletions
+5
View File
@@ -1,3 +1,4 @@
// Package deb implements pkg.Packager providing .deb bindings.
package deb
import (
@@ -14,12 +15,14 @@ import (
"github.com/caarlos0/pkg/tmpl"
)
// Deb is a deb pkg
type Deb struct {
ctx context.Context
Info pkg.Info
Path string
}
// New deb package with the given ctx and info
func New(ctx context.Context, info pkg.Info) (*Deb, error) {
folder, err := ioutil.TempDir("", "deb")
if err != nil {
@@ -33,6 +36,7 @@ func New(ctx context.Context, info pkg.Info) (*Deb, error) {
}, nil
}
// Add adds a file to the package
func (d *Deb) Add(src, dst string) error {
info, err := os.Stat(src)
if err != nil {
@@ -48,6 +52,7 @@ func (d *Deb) Add(src, dst string) error {
return ioutil.WriteFile(filepath.Join(d.Path, dst), bts, info.Mode())
}
// Close closes the package
func (d *Deb) Close() error {
if err := d.createControl(); err != nil {
return err
+4
View File
@@ -1,12 +1,16 @@
// Package pkg provides ways to package programs in some linux packaging
// formats.
package pkg
import "io"
// Packager can package files in some format
type Packager interface {
io.Closer
Add(src, dst string) error
}
// Info contains information about the package
type Info struct {
Filename string
Name string
+2
View File
@@ -1,7 +1,9 @@
// Package tmpl contains templating utilities
package tmpl
import "strings"
// Join joins strings with `, `
func Join(strs []string) string {
return strings.Trim(strings.Join(strs, ", "), " ")
}