ac

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 12 Imported by: 0

README

go-ac

Build Status

ac is helper library that creates CREDITS files(s) using go version -m and gocredits.

Requirement

  • Go 1.13
  • gocredits: if you want to use gocredits as extarnal program.

Ueage

Example of using ac in magefile.

input

  ▾ my-proj/
    ▾ dist/
      ▾ my_cmd_linux_386/
          my_cmd
      ▾ my_cmd_linux_amd64/
          my_cmd
      ▾ my_cmd_windows_amd64/
          my_cmd.exe
      go.sum

output(If CREDITS_* files are all the same, they are merged into the CREDITS file).

  ▾ my-proj/
      CREDITS_Linux_i386
      CREDITS_Linux_amd64
      CREDITS_Windows_amd64

magefile.go

import "github.com/hankei6km/go-ac"

func Credits() error {

	// ...

	cwd, err := os.Getwd()
	if err != nil {
		return err
	}
	tmpDir := filepath.Join(cwd, "tmp")
	if err := ac.ResetDir(tmpDir, os.ModePerm); err != nil {
		return err
	}
	defer os.RemoveAll(tmpDir)

	b := ac.NewOutputBuilder().
		GoSumFile(filepath.Join(cwd, "go.sum"))
	d := ac.NewDistBuilder().
		DistDir(filepath.Join(cwd, "dist")).
		WorkDir(tmpDir).
		ReplaceOs([][]string{
			[]string{"linux", "Linux"},
			[]string{"windows", "Windows"},
		}).
		ReplaceArch([][]string{
			[]string{"386", "i386"},
		}).
		OutDir(cwd).
		OutputBuilder(b).
		Build()
	if err := d.Run(); err != nil {
		return err
	}

	// ...

	return nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DistSuffix

func DistSuffix(d string) []string

DistSuffix returns suffix of d(ie. linux_386 -> [linux 386], linux_amd64_v1 -> [linux amd64_v1])

func ReplaceItem added in v0.1.2

func ReplaceItem(r [][]string, s string) string

ReplaceItem replaces s by r.

func ResetDir

func ResetDir(name string, perm os.FileMode) error

ResetDir calls RemoveAll (if name is exists) and Mkdir.

Types

type Dist

type Dist interface {
	Run() error
}

Dist provide functions to write some CREDITS files for each binary files (ie. foo_linux_386, foo_darwin_amd64 -> CREDITS_linxu_386, CREDITS_darwin_amd64)

Dist は各バイナリファイルから、それぞれ用の CREDITS ファイルを書き出す機能を提供する.

type DistBuilder

type DistBuilder interface {
	WorkDir(string) DistBuilder
	DistDir(string) DistBuilder
	OutDir(string) DistBuilder
	BaseName(string) DistBuilder
	ReplaceOs([][]string) DistBuilder
	ReplaceArch([][]string) DistBuilder
	Uniq(bool) DistBuilder

	OutputBuilder(OutputBuilder) DistBuilder

	OutStream(io.Writer) DistBuilder
	ErrStream(io.Writer) DistBuilder

	Branch() DistBuilder
	Build() Dist
}

DistBuilder builds Dist.

func NewDistBuilder

func NewDistBuilder() DistBuilder

NewDistBuilder returns the instance of DistBuilder.

type FuncOutputBuilder added in v0.1.1

type FuncOutputBuilder interface {
	// contains filtered or unexported methods
}

FuncOutputBuilder adds properties to Output(Builder).

type Output

type Output interface {
	Flush() (hash []byte, err error)
}

Output provides functions to write the CREADITS file from the binary file.

Output はバイナリファイルから CREADTIS ファイルを書き出す機能を提供する.

type OutputBuilder

type OutputBuilder interface {
	GoSumFile(string) OutputBuilder
	WorkDir(string) OutputBuilder
	Binary(string) OutputBuilder
	OutStream(io.Writer) OutputBuilder
	ErrStream(io.Writer) OutputBuilder

	ProgOutput
	FuncOutputBuilder

	Branch() OutputBuilder
	Build() Output
}

OutputBuilder builds CreaditsFile.

今回はそれほどコスト気にする必要はないので、各メソッドで深いコピー(ぽいこと)を行う.

func NewOutputBuilder

func NewOutputBuilder() OutputBuilder

NewOutputBuilder returns the instance of OutputBuilder.

type ProgOutput

type ProgOutput interface {
	Prog(string) OutputBuilder
}

ProgOutput adds properties to Output(Builder).

Jump to

Keyboard shortcuts

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