Commit 8d4ba1fc authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: complete command

parent a8b056e9
......@@ -20,8 +20,8 @@ type CommandServer struct {
}
type CommandRunArgs struct {
RPCAddress string
Args []string
StreamId uint32
}
type CommandSynopsisArgs byte
......@@ -40,11 +40,15 @@ func (c *command) Help() (result string) {
}
func (c *command) Run(env packer.Environment, args []string) (result int) {
// Create and start the server for the Environment
server := rpc.NewServer()
RegisterEnvironment(server, env)
rpcArgs := &CommandRunArgs{serveSingleConn(server), args}
nextId := c.mux.NextId()
server := NewServerWithMux(c.mux, nextId)
server.RegisterEnvironment(env)
go server.Serve()
rpcArgs := &CommandRunArgs{
Args: args,
StreamId: nextId,
}
err := c.client.Call("Command.Run", rpcArgs, &result)
if err != nil {
panic(err)
......@@ -68,14 +72,13 @@ func (c *CommandServer) Help(args *interface{}, reply *string) error {
}
func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error {
client, err := rpcDial(args.RPCAddress)
client, err := NewClientWithMux(c.mux, args.StreamId)
if err != nil {
return err
return NewBasicError(err)
}
defer client.Close()
env := &Environment{client: client}
*reply = c.command.Run(env, args.Args)
*reply = c.command.Run(client.Environment(), args.Args)
return nil
}
......
......@@ -59,11 +59,6 @@ func TestRPCCommand(t *testing.T) {
t.Fatal("runEnv should not be nil")
}
command.runEnv.Ui()
if !testEnv.uiCalled {
t.Fatal("ui should be called")
}
// Test Synopsis
synopsis := commClient.Synopsis()
if synopsis != "foo" {
......
......@@ -30,10 +30,6 @@ type PostProcessorProcessResponse struct {
StreamId uint32
}
func PostProcessor(client *rpc.Client) *postProcessor {
return &postProcessor{client: client}
}
func (p *postProcessor) Configure(raw ...interface{}) (err error) {
args := &PostProcessorConfigureArgs{Configs: raw}
if cerr := p.client.Call("PostProcessor.Configure", args, &err); cerr != nil {
......
......@@ -83,7 +83,7 @@ func TestPostProcessorRPC(t *testing.T) {
func TestPostProcessor_Implements(t *testing.T) {
var raw interface{}
raw = PostProcessor(nil)
raw = new(postProcessor)
if _, ok := raw.(packer.PostProcessor); !ok {
t.Fatal("not a postprocessor")
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment