chore(gonf): add a DECLARED promise status and make it the default instead of PROMISED

This commit is contained in:
Julien Dessaux 2024-09-04 09:11:35 +02:00
parent 48f2e9a2cb
commit 00cb3a2488
Signed by: adyxax
GPG key ID: F92E51B86E07177E
6 changed files with 49 additions and 21 deletions

View file

@ -23,7 +23,7 @@ func CommandWithEnv(env []string, cmd string, args ...string) *CommandPromise {
cmd: cmd,
env: env,
err: nil,
status: PROMISED,
status: DECLARED,
}
}
@ -44,7 +44,10 @@ func (c *CommandPromise) IfRepaired(p ...Promise) Promise {
}
func (c *CommandPromise) Promise() *CommandPromise {
commands = append(commands, c)
if c.status == DECLARED {
c.status = PROMISED
commands = append(commands, c)
}
return c
}

View file

@ -45,7 +45,7 @@ func Directory(filename any) *FilePromise {
filename: interfaceToTemplateValue(filename),
fileType: DIRECTORY,
permissions: nil,
status: PROMISED,
status: DECLARED,
}
}
@ -58,7 +58,7 @@ func File(filename any) *FilePromise {
filename: interfaceToTemplateValue(filename),
fileType: FILE,
permissions: nil,
status: PROMISED,
status: DECLARED,
}
}
@ -88,7 +88,10 @@ func (f *FilePromise) IfRepaired(p ...Promise) Promise {
}
func (f *FilePromise) Promise() *FilePromise {
files = append(files, f)
if f.status == DECLARED {
f.status = PROMISED
files = append(files, f)
}
return f
}

View file

@ -19,7 +19,7 @@ func Package(names ...string) *PackagePromise {
chain: nil,
err: nil,
names: names,
status: PROMISED,
status: DECLARED,
}
}
@ -36,7 +36,10 @@ func (p *PackagePromise) IfRepaired(ps ...Promise) Promise {
}
func (p *PackagePromise) Promise() *PackagePromise {
packages = append(packages, p)
if p.status == DECLARED {
p.status = PROMISED
packages = append(packages, p)
}
return p
}

View file

@ -9,7 +9,8 @@ type Promise interface {
type Status int
const (
PROMISED = iota
DECLARED = iota
PROMISED
BROKEN
KEPT
REPAIRED
@ -17,6 +18,8 @@ const (
func (s Status) String() string {
switch s {
case DECLARED:
return "declared"
case PROMISED:
return "promised"
case BROKEN: