Split main into testable functions

pull/39/head
Christopher Patton 2020-05-30 11:57:56 -07:00
parent cc5012c5af
commit 43f8736f76
1 changed files with 12 additions and 1 deletions

View File

@ -218,7 +218,7 @@ def install_packages(module, packages, use, state, aur_only):
)
def main():
def make_module():
module = AnsibleModule(
argument_spec={
'name': {
@ -274,6 +274,12 @@ def main():
if params.get('upgrade', False) and use == 'makepkg':
module.fail_json(msg="Upgrade cannot be used with the helper 'makepkg'.")
return module, use
def apply_module(module, use):
params = module.params
if module.check_mode:
check_packages(module, params['name'])
elif params.get('upgrade', False):
@ -282,5 +288,10 @@ def main():
install_packages(module, params['name'], use, params['state'], params['aur_only'])
def main():
module, use = make_module()
apply_module(module, use)
if __name__ == '__main__':
main()