recipes

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMax = 9999 // 默认处理文件数量的上限

Variables

View Source
var Get = make(map[string]Recipe)

Functions

func Register

func Register(recipes ...Recipe) error

Types

type MoveNewFiles added in v0.2.0

type MoveNewFiles struct {
	// contains filtered or unexported fields
}

MoveNewFiles 实现了 Recipe 接口,用于把一个文件夹内的 n 个最新文件移动到另一个文件夹。 只能处理一个文件夹内的第一层文件,不会递归搜索子文件夹。

func (*MoveNewFiles) Default added in v0.2.0

func (mv *MoveNewFiles) Default() Options

func (*MoveNewFiles) Exec added in v0.2.0

func (mv *MoveNewFiles) Exec() error

func (*MoveNewFiles) Help added in v0.2.0

func (mv *MoveNewFiles) Help() string

func (*MoveNewFiles) Name added in v0.2.0

func (mv *MoveNewFiles) Name() string

func (*MoveNewFiles) Prepare added in v0.2.0

func (mv *MoveNewFiles) Prepare(names []string, options Options)

Perpare 初始化一些项目,但 mv.n 则需要在 Validate 里初始化。

func (*MoveNewFiles) Refresh added in v0.2.0

func (mv *MoveNewFiles) Refresh()

func (*MoveNewFiles) Validate added in v0.2.0

func (mv *MoveNewFiles) Validate() error

type OneWaySync added in v0.2.0

type OneWaySync struct {
	// contains filtered or unexported fields
}

OneWaySync 实现了 Recipe 接口,用于单向同步。 把 srcFiles (包括文件和文件夹) 同步到 distFolder, distFolder 里没有的文件就 add, 已有的就对比差异按需 update, 多余的则 delete, 其中 add, update, delete 都可以单独控制, true 才执行, false 则不执行(至少一项为 true)。 对于 update 的情况,可选择是否对比日期、是否对比内容(至少对比其中一项)。 如果 dryRun 为 true, 则只显示信息,不实际执行。

func (*OneWaySync) Default added in v0.2.0

func (o *OneWaySync) Default() map[string]string

func (*OneWaySync) Exec added in v0.2.0

func (o *OneWaySync) Exec() error

func (*OneWaySync) Help added in v0.2.0

func (o *OneWaySync) Help() string

func (*OneWaySync) Name added in v0.2.0

func (o *OneWaySync) Name() string

func (*OneWaySync) Prepare added in v0.2.0

func (o *OneWaySync) Prepare(names []string, options map[string]string)

Perpare 初始化一些项目,但 targetDir 与 srcFiles 则需要在 Validate 里初始化。

func (*OneWaySync) Refresh added in v0.2.0

func (o *OneWaySync) Refresh()

func (*OneWaySync) Validate added in v0.2.0

func (o *OneWaySync) Validate() (err error)

type Options added in v0.2.0

type Options = map[string]string

type Recipe

type Recipe interface {

	// Name of this recipe.
	// 注意,应返回一个便于命令行输入的名字,比如中间不要有空格。通常与源码文件名同名即可。
	Name() string

	// Help messages.
	// 方便在命令行查看每个 recipe 的用途。如果没有写清楚,使用者(包括一段时间之后的作者自己)
	// 就需要查看源文件才能知道具体使用方法了。通常用一个带注释的 YAML 文件即可,例子可参考项目自带的 recipe.
	Help() string

	// 清空数据,确保每次被调用的 Recipe 都是全新的,未被污染的。
	Refresh()

	// Default 返回默认的 options
	Default() Options

	// 在 Prepare 里进行一些初始化,为后续的 Validate 和 Exec 做准备。
	// 但由于有些参数需要检查后才能初始化(避免 panic),因此一部分初始化要放在 Validate 里实施。
	Prepare(names []string, options Options)

	// 必须先执行 Prepare 然后才执行 Validate.
	// 注意: 在 Validate 只能读取文件信息,不可修改文件,包括文件内容、日期、权限等等任何修改都不允许。
	// 必须保证 Validate 是安全的,不会对文件进行任何修改的。
	Validate() error

	// 必须先执行 Validate 然后才执行 Exec
	Exec() error
}

Recipe 是一个插件的接口,建议先看看 recipes/swap.go 的具体实现,可以帮助快速理解这个接口。

type Swap

type Swap struct {
	// contains filtered or unexported fields
}

Swap 实现了 Recipe 接口,用于对调两个文件名(或文件夹名)。 Swap 只能用于不需要移动文件的情况,比如同一个文件夹(或同一个硬盘分区)内的文件可以操作, 而跨硬盘分区的文件则无法处理。

func (*Swap) Default

func (s *Swap) Default() Options

func (*Swap) Exec

func (s *Swap) Exec() error

func (*Swap) Help added in v0.2.0

func (s *Swap) Help() string

func (*Swap) Name

func (s *Swap) Name() string

func (*Swap) Prepare

func (s *Swap) Prepare(names []string, options Options)

func (*Swap) Refresh

func (s *Swap) Refresh()

func (*Swap) Validate

func (s *Swap) Validate() (err error)

Jump to

Keyboard shortcuts

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