chore(gonf): add a DECLARED promise status and make it the default instead of PROMISED
This commit is contained in:
parent
48f2e9a2cb
commit
00cb3a2488
6 changed files with 49 additions and 21 deletions
|
@ -23,7 +23,7 @@ func CommandWithEnv(env []string, cmd string, args ...string) *CommandPromise {
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
env: env,
|
env: env,
|
||||||
err: nil,
|
err: nil,
|
||||||
status: PROMISED,
|
status: DECLARED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,10 @@ func (c *CommandPromise) IfRepaired(p ...Promise) Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandPromise) Promise() *CommandPromise {
|
func (c *CommandPromise) Promise() *CommandPromise {
|
||||||
commands = append(commands, c)
|
if c.status == DECLARED {
|
||||||
|
c.status = PROMISED
|
||||||
|
commands = append(commands, c)
|
||||||
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func Directory(filename any) *FilePromise {
|
||||||
filename: interfaceToTemplateValue(filename),
|
filename: interfaceToTemplateValue(filename),
|
||||||
fileType: DIRECTORY,
|
fileType: DIRECTORY,
|
||||||
permissions: nil,
|
permissions: nil,
|
||||||
status: PROMISED,
|
status: DECLARED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func File(filename any) *FilePromise {
|
||||||
filename: interfaceToTemplateValue(filename),
|
filename: interfaceToTemplateValue(filename),
|
||||||
fileType: FILE,
|
fileType: FILE,
|
||||||
permissions: nil,
|
permissions: nil,
|
||||||
status: PROMISED,
|
status: DECLARED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,10 @@ func (f *FilePromise) IfRepaired(p ...Promise) Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FilePromise) Promise() *FilePromise {
|
func (f *FilePromise) Promise() *FilePromise {
|
||||||
files = append(files, f)
|
if f.status == DECLARED {
|
||||||
|
f.status = PROMISED
|
||||||
|
files = append(files, f)
|
||||||
|
}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ func Package(names ...string) *PackagePromise {
|
||||||
chain: nil,
|
chain: nil,
|
||||||
err: nil,
|
err: nil,
|
||||||
names: names,
|
names: names,
|
||||||
status: PROMISED,
|
status: DECLARED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,10 @@ func (p *PackagePromise) IfRepaired(ps ...Promise) Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PackagePromise) Promise() *PackagePromise {
|
func (p *PackagePromise) Promise() *PackagePromise {
|
||||||
packages = append(packages, p)
|
if p.status == DECLARED {
|
||||||
|
p.status = PROMISED
|
||||||
|
packages = append(packages, p)
|
||||||
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ type Promise interface {
|
||||||
type Status int
|
type Status int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PROMISED = iota
|
DECLARED = iota
|
||||||
|
PROMISED
|
||||||
BROKEN
|
BROKEN
|
||||||
KEPT
|
KEPT
|
||||||
REPAIRED
|
REPAIRED
|
||||||
|
@ -17,6 +18,8 @@ const (
|
||||||
|
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
|
case DECLARED:
|
||||||
|
return "declared"
|
||||||
case PROMISED:
|
case PROMISED:
|
||||||
return "promised"
|
return "promised"
|
||||||
case BROKEN:
|
case BROKEN:
|
||||||
|
|
|
@ -33,13 +33,18 @@ type BorgClient struct {
|
||||||
status gonf.Status
|
status gonf.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var borgClient *BorgClient = nil
|
||||||
|
|
||||||
func (b *BorgClient) IfRepaired(p ...gonf.Promise) gonf.Promise {
|
func (b *BorgClient) IfRepaired(p ...gonf.Promise) gonf.Promise {
|
||||||
b.chain = append(b.chain, p...)
|
b.chain = append(b.chain, p...)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BorgClient) Promise() *BorgClient {
|
func (b *BorgClient) Promise() *BorgClient {
|
||||||
gonf.MakeCustomPromise(b).Promise()
|
if b.status == gonf.DECLARED {
|
||||||
|
b.status = gonf.PROMISED
|
||||||
|
gonf.MakeCustomPromise(b).Promise()
|
||||||
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +106,15 @@ func (b BorgClient) Status() gonf.Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Client() *BorgClient {
|
func Client() *BorgClient {
|
||||||
return &BorgClient{
|
if borgClient == nil {
|
||||||
chain: nil,
|
borgClient = &BorgClient{
|
||||||
jobs: make(map[string]*Job),
|
chain: nil,
|
||||||
path: "/etc/borg/",
|
jobs: make(map[string]*Job),
|
||||||
status: gonf.PROMISED,
|
path: "/etc/borg/",
|
||||||
|
status: gonf.DECLARED,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return borgClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BorgClient) Add(name string, path string, privateKey []byte, hostname string) *BorgClient {
|
func (b *BorgClient) Add(name string, path string, privateKey []byte, hostname string) *BorgClient {
|
||||||
|
|
|
@ -15,13 +15,18 @@ type BorgServer struct {
|
||||||
status gonf.Status
|
status gonf.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var borgServer *BorgServer = nil
|
||||||
|
|
||||||
func (b *BorgServer) IfRepaired(p ...gonf.Promise) gonf.Promise {
|
func (b *BorgServer) IfRepaired(p ...gonf.Promise) gonf.Promise {
|
||||||
b.chain = append(b.chain, p...)
|
b.chain = append(b.chain, p...)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BorgServer) Promise() *BorgServer {
|
func (b *BorgServer) Promise() *BorgServer {
|
||||||
gonf.MakeCustomPromise(b).Promise()
|
if b.status == gonf.DECLARED {
|
||||||
|
b.status = gonf.PROMISED
|
||||||
|
gonf.MakeCustomPromise(b).Promise()
|
||||||
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,13 +85,16 @@ func (b BorgServer) Status() gonf.Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Server() *BorgServer {
|
func Server() *BorgServer {
|
||||||
return &BorgServer{
|
if borgServer == nil {
|
||||||
chain: nil,
|
borgServer = &BorgServer{
|
||||||
clients: make(map[string][]byte),
|
chain: nil,
|
||||||
path: "/srv/borg/",
|
clients: make(map[string][]byte),
|
||||||
user: "borg",
|
path: "/srv/borg/",
|
||||||
status: gonf.PROMISED,
|
user: "borg",
|
||||||
|
status: gonf.DECLARED,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return borgServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BorgServer) Add(name string, publicKey []byte) *BorgServer {
|
func (b *BorgServer) Add(name string, publicKey []byte) *BorgServer {
|
||||||
|
|
Loading…
Add table
Reference in a new issue