summaryrefslogtreecommitdiffstats
path: root/cli/objects/modes.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-11-21 16:46:18 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-11-21 17:05:24 +0100
commit10a3897f92ee058155987cea23eec28b28377d4b (patch)
tree9bbc4f0bb696adbb4c97b5c524b674eff8d1a853 /cli/objects/modes.py
parentea8210a805e860154e8b0b9446bdd30043b893e6 (diff)
cli: ensure the program returns 0 on success and 1 on error
propagate a returncode in each operation and make it the returncode of the program. Prevent sys.exit calls in post(), get() and delete() request handlers to enable cleanup code and error handling. Keep a basic error log inside the request functions if the connection can't be established or if the response contains an error code.
Diffstat (limited to 'cli/objects/modes.py')
-rw-r--r--cli/objects/modes.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/cli/objects/modes.py b/cli/objects/modes.py
index 7cf78e2..2374777 100644
--- a/cli/objects/modes.py
+++ b/cli/objects/modes.py
@@ -14,8 +14,11 @@ class OgModes():
@staticmethod
def list_available_modes(rest):
- r = rest.get('/mode')
- print_json(r.text)
+ res = rest.get('/mode')
+ if not res:
+ return 1
+ print_json(res.text)
+ return 0
@staticmethod
def set_modes(rest, args):
@@ -44,8 +47,8 @@ class OgModes():
help='Boot mode to be set')
parsed_args = parser.parse_args(args)
- r = rest.get('/scopes')
- scopes = r.json()
+ res = rest.get('/scopes')
+ scopes = res.json()
ips = set()
for center in parsed_args.center_id:
@@ -59,7 +62,10 @@ class OgModes():
if not ips:
print("Missing --client-ip, or --room-id/--center-id. No clients provided.")
- return None
+ return 1
payload = {'clients': list(ips), 'mode': parsed_args.mode[0]}
- r = rest.post('/mode', payload=payload)
+ res = rest.post('/mode', payload=payload)
+ if not res:
+ return 1
+ return 0