]> git.ipfire.org Git - location/libloc.git/commitdiff
location-query: Require at least one flag
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Jun 2020 16:15:24 +0000 (16:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Jun 2020 16:15:24 +0000 (16:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-query.in

index 5f05b5cdb68327812131f3e6e6f93b3645be83c2..dfdff8c2b804b08732d7734c310a1614cc35d3e9 100644 (file)
@@ -246,7 +246,13 @@ class CLI(object):
                                args.family = 0
 
                # Call function
-               ret = args.func(db, args)
+               try:
+                       ret = args.func(db, args)
+
+               # Catch invalid inputs
+               except ValueError as e:
+                       sys.stderr.write("%s\n" % e)
+                       ret = 2
 
                # Return with exit code
                if ret:
@@ -451,6 +457,9 @@ class CLI(object):
                if ns.anycast:
                        flags |= location.NETWORK_FLAG_ANYCAST
 
+               if not flags:
+                       raise ValueError(_("You must at least pass one flag"))
+
                with self.__get_output_formatter(ns) as f:
                        for n in db.search_networks(flags=flags, family=ns.family):
                                f.network(n)