]> granicus.if.org Git - pdns/commitdiff
Improve commandline error reporting for non-opts
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 10 Sep 2019 15:26:35 +0000 (17:26 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 10 Sep 2019 15:26:35 +0000 (17:26 +0200)
Before:

```
pdns_server --launch=random --socket-dir=. foo
Fatal: non-option on the command line, perhaps a '--setting=123' statement missed the '='?
```

After:
```
pdns_server --launch=random --socket-dir=. bar
Sep 10 17:24:25 Unable to open /usr/local/etc/pdns.conf
Fatal: non-options (bar) on the command line, perhaps a '--setting=123' statement missed the '='?

pdns_server --launch=random --socket-dir=. bar foo
Sep 10 17:24:25 Unable to open /usr/local/etc/pdns.conf
Fatal: non-options (bar, foo) on the command line, perhaps a '--setting=123' statement missed the '='?
```

pdns/pdns_recursor.cc
pdns/receiver.cc

index 0b7a8f098b14c4e8cd3674e4338c35d478915be2..78d569df050b3fe949f35bea735d55cfc21fdba6 100644 (file)
@@ -4646,7 +4646,20 @@ int main(int argc, char **argv)
     cleanSlashes(configname);
 
     if(!::arg().getCommands().empty()) {
-      cerr<<"Fatal: non-option on the command line, perhaps a '--setting=123' statement missed the '='?"<<endl;
+      cerr<<"Fatal: non-option";
+      if (::arg().getCommands().size() > 1) {
+        cerr<<"s";
+      }
+      cerr<<" (";
+      bool first = true;
+      for (auto const c : ::arg().getCommands()) {
+        if (!first) {
+          cerr<<", ";
+        }
+        first = false;
+        cerr<<c;
+      }
+      cerr<<") on the command line, perhaps a '--setting=123' statement missed the '='?"<<endl;
       exit(99);
     }
 
index c7b2af93e48b0bd1f824403afd40721344784ee1..2698076fb0cde2d9ba7dbaa40b5b09bc289d30be 100644 (file)
@@ -488,7 +488,20 @@ int main(int argc, char **argv)
     BackendMakers().launch(::arg()["launch"]); // vrooooom!
 
     if(!::arg().getCommands().empty()) {
-      cerr<<"Fatal: non-option on the command line, perhaps a '--setting=123' statement missed the '='?"<<endl;
+      cerr<<"Fatal: non-option";
+      if (::arg().getCommands().size() > 1) {
+        cerr<<"s";
+      }
+      cerr<<" (";
+      bool first = true;
+      for (auto const c : ::arg().getCommands()) {
+        if (!first) {
+          cerr<<", ";
+        }
+        first = false;
+        cerr<<c;
+      }
+      cerr<<") on the command line, perhaps a '--setting=123' statement missed the '='?"<<endl;
       exit(99);
     }