Skip to content

Commit

Permalink
Cpud double check args (#246)
Browse files Browse the repository at this point in the history
* ds: improve the message when a service is not found

Show the service that was requested. In the case of default,
users need to see the name.

Signed-off-by: Ronald G Minnich <[email protected]>

* cmds/cpud: clean up handling of -remote

If the first arg is -remote=true or -remote,
this is a remote session. At that point, no
other settings of -remote in the args will have
any effect.

This change is necessary as pathological commands
such as
cpud -remote -d -remote=false
will cause incorrect behavior.

The command line options that can now be set from the cpu
command are:
-remote
-port9p
-d

The only one that would be sensible for a user to set
from the command line:
-d

Users wishing to get debug output can, e.g.:
cpu -d hostname command

Signed-off-by: Ronald G Minnich <[email protected]>

---------

Signed-off-by: Ronald G Minnich <[email protected]>
  • Loading branch information
rminnich authored Sep 15, 2023
1 parent 8962908 commit 82a5c62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cmds/cpud/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func verbose(f string, a ...interface{}) {
// the args to remote and the args to server are different.
// This invocation requirement is known to the server package.
func main() {
if len(os.Args) > 1 && os.Args[1] == "-remote" {
if len(os.Args) > 1 && (os.Args[1] == "-remote" || os.Args[1] == "-remote=true") {
*remote = true
}

Expand All @@ -78,8 +78,13 @@ func main() {
v = log.Printf
session.SetVerbose(verbose)
}
// If we are here, no matter what they may set, *remote must be true.
// sadly, cpud -d -remote=true -remote=false ... works.
*remote = true
} else {
flag.Parse()
// If we are here, no matter what they may set, *remote must be false.
*remote = false
if err := commonsetup(); err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ds/ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func Lookup(query dsQuery, n int) ([]*LookupResult, error) {
dnssd.LookupType(ctx, service, addFn, rmvFn)

if len(responses) == 0 {
return nil, fmt.Errorf("dnssd found no suitable service %w", os.ErrNotExist)
return nil, fmt.Errorf("dnssd: %q: %w", service, os.ErrNotExist)
}

dsSort(query.Text, responses)
Expand Down

0 comments on commit 82a5c62

Please sign in to comment.