Skip to content

Commit

Permalink
fix: display cd errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Jan 17, 2025
1 parent 394e5e4 commit 59d5682
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
7 changes: 4 additions & 3 deletions core/lib/agent/ccHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
57 changes: 31 additions & 26 deletions core/lib/cc/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())),

Expand Down Expand Up @@ -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())),
}
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions core/lib/cc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type Command struct {
// CommandMap holds all commands
var CommandMap = map[string]Command{
HELP: {
Name: HELP,
Help: "Print this help, 'help <module>' gives help for a module",
Func: nil,
Name: HELP,
Help: "Print this help, 'help <module>' gives help for a module",
Func: nil,
HasArg: true,
},
"target": {
Name: "target",
Expand Down

0 comments on commit 59d5682

Please sign in to comment.