-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.go
34 lines (28 loc) · 849 Bytes
/
flag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package engine
import (
"github.com/juju/errors"
"github.com/juju/juju/worker"
)
// Flag represents a single boolean used to determine whether a given
// manifold worker should run.
type Flag interface {
// Check returns the flag's value. Check calls must *always* return
// the same value for a given instatiation of the type implementing
// Flag.
Check() bool
}
// FlagOutput will expose, as a Flag, any worker that implements Flag.
func FlagOutput(in worker.Worker, out interface{}) error {
inFlag, ok := in.(Flag)
if !ok {
return errors.Errorf("expected in to implement Flag; got a %T", in)
}
outFlag, ok := out.(*Flag)
if !ok {
return errors.Errorf("expected out to be a *Flag; got a %T", out)
}
*outFlag = inFlag
return nil
}