Input outside of a unit
This commit is contained in:
parent
509f281f72
commit
6c8fd03a69
|
@ -1,17 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
"code.google.com/p/go.net/context"
|
"code.google.com/p/go.net/context"
|
||||||
"github.com/localhots/yeast/core"
|
"github.com/localhots/yeast/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var num int
|
||||||
|
flag.IntVar(&num, "num", 0, "Pass this number")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
chain, ok := core.NewChain("calculate")
|
chain, ok := core.NewChain("calculate")
|
||||||
if !ok {
|
if !ok {
|
||||||
println("Bad chain: calculate")
|
println("Bad chain: calculate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.WithValue(context.Background(), "num", num)
|
||||||
core.ProcessChain(ctx, chain)
|
core.ProcessChain(ctx, chain)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
"calculate": {
|
"calculate": {
|
||||||
"s": [
|
"s": [
|
||||||
"uuid",
|
"uuid",
|
||||||
"input_from_flag",
|
|
||||||
{
|
{
|
||||||
"p": [
|
"p": [
|
||||||
"power2",
|
"power2",
|
||||||
|
|
|
@ -3,7 +3,6 @@ package core
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/go.net/context"
|
"code.google.com/p/go.net/context"
|
||||||
"github.com/localhots/yeast/units/aggregator"
|
"github.com/localhots/yeast/units/aggregator"
|
||||||
"github.com/localhots/yeast/units/input"
|
|
||||||
"github.com/localhots/yeast/units/logger"
|
"github.com/localhots/yeast/units/logger"
|
||||||
"github.com/localhots/yeast/units/power"
|
"github.com/localhots/yeast/units/power"
|
||||||
"github.com/localhots/yeast/units/sleep"
|
"github.com/localhots/yeast/units/sleep"
|
||||||
|
@ -21,7 +20,6 @@ var (
|
||||||
"power2": power.Power2,
|
"power2": power.Power2,
|
||||||
"power3": power.Power3,
|
"power3": power.Power3,
|
||||||
"power5": power.Power5,
|
"power5": power.Power5,
|
||||||
"input_from_flag": input.FromFlag,
|
|
||||||
"sleep": sleep.Call,
|
"sleep": sleep.Call,
|
||||||
"uuid": uuid.Call,
|
"uuid": uuid.Call,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package input
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
|
|
||||||
"code.google.com/p/go.net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
func FromFlag(ctx context.Context) context.Context {
|
|
||||||
var num int
|
|
||||||
flag.IntVar(&num, "num", 0, "Pass this number")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
ctx = context.WithValue(ctx, "num", num)
|
|
||||||
|
|
||||||
return ctx
|
|
||||||
}
|
|
Loading…
Reference in New Issue