mirror of https://gogs.blitter.com/RLabs/xs
Initial (buggy) support for 'fancy arg' style ala ssh: eg user@example.org:port:path
This commit is contained in:
parent
f48b0c17ed
commit
5eb7d4d1e6
|
@ -35,6 +35,7 @@ type cmdSpec struct {
|
|||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
defPort = "2000"
|
||||
)
|
||||
|
||||
// Get terminal size using 'stty' command
|
||||
|
@ -52,6 +53,53 @@ func GetSize() (cols, rows int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func parseFancyEndpointArg(a []string, dp string) (user, host, port, path string) {
|
||||
//TODO: Look for non-option fancyArg of syntax user@host:filespec to set -r,-t and -u
|
||||
// Consider: whether fancyArg is src or dst file depends on flag.Args() index;
|
||||
// fancyArg as last flag.Args() element denotes dstFile
|
||||
// fancyArg as not-last flag.Args() element denotes srcFile
|
||||
// * throw error if >1 fancyArgs are found in flags.Args()
|
||||
var fancyUser, fancyHost, fancyPort, fancyPath string
|
||||
for i, arg := range flag.Args() {
|
||||
if strings.Contains(arg, ":") || strings.Contains(arg, "@") {
|
||||
fancyArg := strings.Split(flag.Arg(i), "@")
|
||||
var fancyHostPortPath []string
|
||||
if len(fancyArg) < 2 {
|
||||
//TODO: no user specified, use current
|
||||
fancyUser = "[default:getUser]"
|
||||
fancyHostPortPath = strings.Split(fancyArg[0], ":")
|
||||
} else {
|
||||
// user@....
|
||||
fancyUser = fancyArg[0]
|
||||
fancyHostPortPath = strings.Split(fancyArg[1], ":")
|
||||
}
|
||||
|
||||
if len(fancyHostPortPath) > 2 {
|
||||
// [user]@host[:port]:path
|
||||
fancyPath = fancyHostPortPath[2]
|
||||
}
|
||||
if len(fancyHostPortPath) > 1 {
|
||||
// [user]@host:port[:...] or [user]@host:path (default port)
|
||||
fancyPort = fancyHostPortPath[1]
|
||||
}
|
||||
// [user]@host[:...[:...]]
|
||||
fancyHost = fancyHostPortPath[0]
|
||||
|
||||
if fancyPort == "" {
|
||||
fancyPort = dp
|
||||
}
|
||||
|
||||
if fancyPath == "" {
|
||||
fancyPath = "."
|
||||
}
|
||||
|
||||
fmt.Println("fancyArgs: user:", fancyUser, "host:", fancyHost, "port:", fancyPort, "path:", fancyPath)
|
||||
break // ignore multiple 'fancyArgs'
|
||||
}
|
||||
}
|
||||
return fancyUser, fancyHost, fancyPort, fancyPath
|
||||
}
|
||||
|
||||
// Demo of a simple client that dials up to a simple test server to
|
||||
// send data.
|
||||
//
|
||||
|
@ -90,7 +138,7 @@ func main() {
|
|||
flag.BoolVar(&dbg, "d", false, "debug logging")
|
||||
flag.StringVar(&cAlg, "c", "C_AES_256", "cipher [\"C_AES_256\" | \"C_TWOFISH_128\" | \"C_BLOWFISH_64\"]")
|
||||
flag.StringVar(&hAlg, "m", "H_SHA256", "hmac [\"H_SHA256\"]")
|
||||
flag.StringVar(&server, "s", "localhost:2000", "server hostname/address[:port]")
|
||||
flag.StringVar(&server, "s", "localhost:"+defPort, "server hostname/address[:port]")
|
||||
flag.StringVar(&altUser, "u", "", "specify alternate user")
|
||||
flag.StringVar(&authCookie, "a", "", "auth cookie")
|
||||
flag.BoolVar(&chaffEnabled, "e", true, "enabled chaff pkts (default true)")
|
||||
|
@ -100,19 +148,35 @@ func main() {
|
|||
|
||||
// Find out what program we are (shell or copier)
|
||||
myPath := strings.Split(os.Args[0], string(os.PathSeparator))
|
||||
if myPath[len(myPath)-1] != "hkexcp" {
|
||||
if myPath[len(myPath)-1] != "hkexcp" && myPath[len(myPath)-1] != "hkexcp.exe" {
|
||||
// hkexsh accepts a command (-x) but not
|
||||
// a srcpath (-r) or dstpath (-t)
|
||||
flag.StringVar(&cmdStr, "x", "", "command to run (default empty - interactive shell)")
|
||||
flag.Parse()
|
||||
} else {
|
||||
// hkexcp accepts srcpath (-r) and dstpath (-t), but not
|
||||
// a command (-x)
|
||||
flag.StringVar(©Src, "r", "", "copy srcpath")
|
||||
flag.StringVar(©Dst, "t", "", "copy dstpath")
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
if flag.NFlag() == 0 {
|
||||
fancyUser, fancyHost, fancyPort, fancyPath := parseFancyEndpointArg(flag.Args(), defPort /* defPort */)
|
||||
fmt.Println("fancyHost:", fancyHost)
|
||||
if fancyUser != "" {
|
||||
altUser = fancyUser
|
||||
}
|
||||
if fancyHost != "" {
|
||||
server = fancyHost + ":" + fancyPort
|
||||
fmt.Println("fancyHost sets server to", server)
|
||||
}
|
||||
if fancyPath != "" {
|
||||
//TODO: srcPath or dstPath depends on other flag.Args
|
||||
copyDst = fancyPath
|
||||
}
|
||||
|
||||
fmt.Println("server finally is:", server)
|
||||
|
||||
if flag.NFlag() == 0 && server == "" {
|
||||
flag.Usage()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue