CLI: must_be_root: extract logic to own function.

parent e69ab5a7
......@@ -19,12 +19,14 @@ class Command(cliff.command.Command):
return parser
def check_root_user(config_command_instance):
if sys.platform != 'cygwin' and os.getuid() != 0:
config_command_instance.app.log.error('This slapos command must be run as root.')
sys.exit(5)
def must_be_root(func):
@functools.wraps(func)
def inner(self, *args, **kw):
if sys.platform != 'cygwin' and os.getuid() != 0:
self.app.log.error('This slapos command must be run as root.')
sys.exit(5)
check_root_user(self)
return func(self, *args, **kw)
return inner
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment