diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-18 19:18:37 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-18 19:18:37 (GMT) |
commit | f2cb74e053c70e5edde771f5efdd75cbf5c4e4cb (patch) | |
tree | 15abbf02435878e069d8cd1e20433f7c89f177ce | |
parent | 1b93ccfa1f4ef996e7009874127fde0a3c9a2d77 (diff) |
show command is now implemented for telnet client
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlTelnet.go | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go index 4d60fe2..93cd25b 100644 --- a/src/helsinki.at/rhimportd/ctrlTelnet.go +++ b/src/helsinki.at/rhimportd/ctrlTelnet.go @@ -33,7 +33,7 @@ import ( ) const ( - prompt = "rhimportd> " + prompt = "> " ) type TelnetClient struct { @@ -52,39 +52,61 @@ func (c *TelnetClient) write_string(text string) (err error) { return c.writer.Flush() } -func (c *TelnetClient) say(text string) (err error) { - return c.write_string(text + "\n") +func (c *TelnetClient) say(format string, a ...interface{}) (err error) { + return c.write_string(fmt.Sprintf(format, a...) + "\n") } func (c *TelnetClient) handle_cmd_help(args []string) { - c.say(fmt.Sprintf("usage: tba...(args: %v)", args)) + c.say("usage: tba...(args: %v)", args) } func (c *TelnetClient) handle_cmd_set(args []string) { - c.say(fmt.Sprintf("setting args: %v", args)) + c.say("setting args: %v", args) if c.ctx == nil { c.ctx = &rhimport.ImportContext{Config: c.conf, RdDb: c.rddb} c.ctx.UserName = "hugo" } } -func (c *TelnetClient) handle_cmd_clear(args []string) { - if len(args) >= 0 { +func (c *TelnetClient) handle_cmd_reset(args []string) { + if len(args) > 0 { c.say("too many arguments") + return } c.ctx = nil } func (c *TelnetClient) handle_cmd_show(args []string) { - c.say(fmt.Sprintf("%+v", c.ctx)) + if len(args) > 0 { + c.say("too many arguments") + return + } + if c.ctx != nil { + c.say(" UserName: %v", c.ctx.UserName) + c.say(" Password: %v", c.ctx.Password) + c.say(" Trusted: %v", c.ctx.Trusted) + c.say(" ShowId: %v", c.ctx.ShowId) + c.say(" ClearShowCarts: %v", c.ctx.ClearShowCarts) + c.say(" GroupName: %v", c.ctx.GroupName) + c.say(" Cart: %v", c.ctx.Cart) + c.say(" ClearCart: %v", c.ctx.ClearCart) + c.say(" Cut: %v", c.ctx.Cut) + c.say(" Channels: %v", c.ctx.Channels) + c.say(" NormalizationLevel: %v", c.ctx.NormalizationLevel) + c.say(" AutotrimLevel: %v", c.ctx.AutotrimLevel) + c.say(" UseMetaData: %v", c.ctx.UseMetaData) + c.say(" SourceUri: %v", c.ctx.SourceUri) + } else { + c.say("context is empty") + } } func (c *TelnetClient) handle_cmd_run(args []string) { if c.ctx != nil { - c.say(fmt.Sprintf("running args: %v", args)) + c.say("running args: %v", args) c.ctx = nil } else { - c.say(fmt.Sprintf("context is empty please set at least one option")) + c.say("context is empty please set at least one option") } } @@ -102,8 +124,8 @@ func (c *TelnetClient) handle_cmd(cmdstr string) bool { c.handle_cmd_help(args) } else if cmd == "set" { c.handle_cmd_set(args) - } else if cmd == "clear" { - c.handle_cmd_clear(args) + } else if cmd == "reset" { + c.handle_cmd_reset(args) } else if cmd == "show" { c.handle_cmd_show(args) } else if cmd == "run" { |