p9
p9 copied to clipboard
cmd/p9: allow implicit address in paths
Currently, the only way to specify an address to connect to is to use the -addr flag. This is not a problem, per se, but I think it might be useful to also be able to imply the address in the argument itself when only dealing with a single argument if the -addr flag isn't specified. For example, running p9 ls -l ./example.sock/path/to/a/file would dial example.sock and then request path/to/a/file. I think that a simple heuristic for determining what to do should work for most cases:
- If the path starts with
./, assume that it is a Unix socket relative to the current directory. Traverse the path one element at a time until that socket is found, then dial it and use the remainder of the path for the request. - If the path starts with
/, assume that it is an absolute path to a Unix socket. Find it in the same was as for./. - If the path does not start with a slash but contains a colon before the first slash, assume everything before the first slash is a TCP address.
- If the path does not start with a slash but contains a
!, assume that separates a network type from an address. If it is a Unix network, find it in the same way as above. If it contains two!, assume that the second separates a port number and replace it with a:. - If it does not start with a slash and does not contain a
:or a!and doesn't seem to point to an existing Unix socket, assume that the first element is a Plan 9 namespace and look it up as appropriate.
The existing parseAddr() function can be reworked to have this functionality. That should simplify implementation and ensure consistency in how the dialing works.