def test_getting_context_file_handles_invalid_syntax(self): context.get_config_file = lambda name: '--in-application\n' ret = context.get_context_dict() self.assertEquals(ret, {})
def test_getting_context_file(self): context.get_config_file = lambda _: '--in-application = test\n' ret = context.get_context_dict() self.assertEquals(ret, {'--in-application': 'test'})
def main(): arguments = docopt(__doc__) action = arguments.get('<action>') resource = arguments.get('<resource>') log = setup_output(arguments.get('--verbose')) arguments.update(get_context_dict()) arguments, resource, action = find_non_dash_arguments_and_default_action( arguments, resource, action) arguments = properly_support_boolean_values(arguments) arguments = check_primary_identifier_without_flags(arguments, resource, action) if not action: log.error(__doc__.strip('\n')) return -1 if action == 'help': log.error(__doc__.strip('\n')) return -1 if action not in AVAILABLE_ACTIONS: log.error( "Unknown action '{}'. See 'stormpath --help' for list of available actions." .format(action)) return -1 if action in LOCAL_ACTIONS: return 0 if AVAILABLE_ACTIONS[action](arguments) else -1 if not resource and action != STATUS_ACTION: if action == SET_ACTION: log.error( "A resource type is required. Available resources for the set command are: application, directory. Please see 'stormpath --help'" ) return -1 log.error( "A resource type is required. Available resources: {}. Please see 'stormpath --help'" .format(', '.join(sorted(AVAILABLE_RESOURCES.keys())))) return -1 if resource not in AVAILABLE_RESOURCES and action != STATUS_ACTION: log.error( "Unknown resource type '{}'. See 'stormpath --help' for list of available resource types." .format(resource)) return -1 try: auth_args = init_auth(arguments) client = Client(user_agent=USER_AGENT, **auth_args) except ValueError as ex: log.error(str(ex)) return -1 if action == STATUS_ACTION: return 0 if AVAILABLE_ACTIONS[action](client, arguments) else -1 try: res = AVAILABLE_RESOURCES[resource](client, arguments) except ValueError as ex: log.error(str(ex)) return -1 act = AVAILABLE_ACTIONS[action] try: result = act(res, arguments) except (StormpathError, ValueError) as ex: log.error(str(ex)) return -1 if result is not None and (isinstance(result, list) or isinstance( result, dict) or isinstance(result, types.GeneratorType)): output(result, show_links=arguments.get('--show-links', False), show_headers=arguments.get('--show-headers', False), output_json=arguments.get('--output-json', False)) return 0
def main(): arguments = docopt(__doc__) action = arguments.get('<action>') resource = arguments.get('<resource>') log = setup_output(arguments.get('--verbose')) arguments.update(get_context_dict()) arguments = strip_equal_sign(arguments) if resource and resource.find('=') != -1: # Workaround for when list command is not specified # and non-dash attributes are used arguments['<attributes>'].append(resource) arguments['<resource>'] = None resource = None if action in AVAILABLE_RESOURCES and not resource: resource = action action = DEFAULT_ACTION if not action: log.error(__doc__.strip('\n')) return -1 if action not in AVAILABLE_ACTIONS: log.error("Unknown action '%s'. See 'stormpath --help' for list of " "available actions." % action) return -1 if action in LOCAL_ACTIONS: return 0 if AVAILABLE_ACTIONS[action](arguments) else -1 if not resource: log.error("A resource type is required. Available resources: %s. " "Please see 'stormpath --help'" % ", ".join(sorted(AVAILABLE_RESOURCES.keys()))) return -1 if resource not in AVAILABLE_RESOURCES: log.error("Unknown resource type '%s'. See 'stormpath --help' for " "list of available resource types." % resource) return -1 try: auth_args = init_auth(arguments) client = Client(user_agent=USER_AGENT, **auth_args) except ValueError as ex: log.error(str(ex)) return -1 try: res = AVAILABLE_RESOURCES[resource](client, arguments) except ValueError as ex: log.error(str(ex)) return -1 act = AVAILABLE_ACTIONS[action] try: result = act(res, arguments) except (StormpathError, ValueError) as ex: log.error(str(ex)) return -1 if result is not None and (isinstance(result, list) or isinstance(result, dict)): output(result, show_links=arguments.get('--show-links', False)) return 0
def main(): arguments = docopt(__doc__) action = arguments.get('<action>') resource = arguments.get('<resource>') log = setup_output(arguments.get('--verbose')) arguments.update(get_context_dict()) arguments, resource, action = find_non_dash_arguments_and_default_action(arguments, resource, action) arguments = properly_support_boolean_values(arguments) arguments = check_primary_identifier_without_flags(arguments, resource, action) if not action: log.error(__doc__.strip('\n')) return -1 if action == 'help': log.error(__doc__.strip('\n')) return -1 if action not in AVAILABLE_ACTIONS: log.error("Unknown action '{}'. See 'stormpath --help' for list of available actions.".format(action)) return -1 if action in LOCAL_ACTIONS: return 0 if AVAILABLE_ACTIONS[action](arguments) else -1 if not resource and action != STATUS_ACTION: if action == SET_ACTION: log.error("A resource type is required. Available resources for the set command are: application, directory. Please see 'stormpath --help'") return -1 log.error("A resource type is required. Available resources: {}. Please see 'stormpath --help'".format(', '.join(sorted(AVAILABLE_RESOURCES.keys())))) return -1 if resource not in AVAILABLE_RESOURCES and action != STATUS_ACTION: log.error("Unknown resource type '{}'. See 'stormpath --help' for list of available resource types.".format(resource)) return -1 try: auth_args = init_auth(arguments) client = Client(user_agent=USER_AGENT, **auth_args) except ValueError as ex: log.error(str(ex)) return -1 if action == STATUS_ACTION: return 0 if AVAILABLE_ACTIONS[action](client, arguments) else -1 try: res = AVAILABLE_RESOURCES[resource](client, arguments) except ValueError as ex: log.error(str(ex)) return -1 act = AVAILABLE_ACTIONS[action] try: result = act(res, arguments) except (StormpathError, ValueError) as ex: log.error(str(ex)) return -1 if result is not None and ( isinstance(result, list) or isinstance(result, dict) or isinstance(result, types.GeneratorType)): output( result, show_links=arguments.get('--show-links', False), show_headers=arguments.get('--show-headers', False), output_json=arguments.get('--output-json', False)) return 0