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