def _validate_pos_args_syntax(alias_name, alias_command):
    """
    Check if the positional argument syntax is valid in alias name and alias command.

    Args:
        alias_name: The name of the alias to validate.
        alias_command: The command to validate.
    """
    pos_args_from_alias = get_placeholders(alias_name)
    # Split by '|' to extract positional argument name from Jinja filter (e.g. {{ arg_name | upper }})
    # Split by '.' to extract positional argument name from function call (e.g. {{ arg_name.split()[0] }})
    pos_args_from_command = [x.split('|')[0].split('.')[0].strip() for x in get_placeholders(alias_command)]

    if set(pos_args_from_alias) != set(pos_args_from_command):
        arg_diff = set(pos_args_from_alias) ^ set(pos_args_from_command)
        raise CLIError(INCONSISTENT_ARG_ERROR.format('' if len(arg_diff) == 1 else 's',
                                                     arg_diff,
                                                     'is' if len(arg_diff) == 1 else 'are'))
def _validate_pos_args_syntax(alias_name, alias_command):
    """
    Check if the positional argument syntax is valid in alias name and alias command.

    Args:
        alias_name: The name of the alias to validate.
        alias_command: The command to validate.
    """
    pos_args_from_alias = get_placeholders(alias_name)
    # Split by '|' to extract positional argument name from Jinja filter (e.g. {{ arg_name | upper }})
    # Split by '.' to extract positional argument name from function call (e.g. {{ arg_name.split()[0] }})
    pos_args_from_command = [x.split('|')[0].split('.')[0].strip() for x in get_placeholders(alias_command)]

    if set(pos_args_from_alias) != set(pos_args_from_command):
        arg_diff = set(pos_args_from_alias) ^ set(pos_args_from_command)
        raise CLIError(INCONSISTENT_ARG_ERROR.format('' if len(arg_diff) == 1 else 's',
                                                     arg_diff,
                                                     'is' if len(arg_diff) == 1 else 'are'))
 def test_get_placeholders_no_closing_bracket(self):
     with self.assertRaises(CLIError):
         get_placeholders('{{ arg_1 ')
 def test_get_placeholders_double_opening_bracket(self):
     with self.assertRaises(CLIError):
         get_placeholders('{{ {{ arg_1')
 def test_get_placeholders_no_opening_bracket(self):
     with self.assertRaises(CLIError):
         get_placeholders('arg_1 }}')
 def test_get_placeholders_duplicate(self):
     with self.assertRaises(CLIError):
         get_placeholders('{{ arg_1 }} {{ arg_1 }}', check_duplicates=True)
 def test_get_placeholders_with_strings_and_numbers(self):
     self.assertListEqual(
         ['_0', '_1', 'arg_1', 'arg_2'],
         get_placeholders('{{ 0 }} {{ 1 }} {{ arg_1 }} {{ arg_2 }}'))
 def test_get_placeholders_with_numbers(self):
     self.assertListEqual(['_0', '_1'], get_placeholders('{{ 0 }} {{ 1 }}'))
 def test_get_placeholders(self):
     self.assertListEqual(['arg_1', 'arg_2'],
                          get_placeholders('{{ arg_1 }} {{ arg_2 }}'))
 def test_get_placeholders_no_closing_bracket(self):
     with self.assertRaises(CLIError) as cm:
         get_placeholders('{{ arg_1 ')
     self.assertEqual(str(cm.exception), 'alias: Brackets in "{{ arg_1 " are not enclosed properly')
 def test_get_placeholders_duplicate(self):
     with self.assertRaises(CLIError) as cm:
         get_placeholders('{{ arg_1 }} {{ arg_1 }}', check_duplicates=True)
     self.assertEqual(str(cm.exception), 'alias: Duplicated placeholders found when transforming "{{ arg_1 }} {{ arg_1 }}"')
 def test_get_placeholders_with_strings_and_numbers(self):
     self.assertListEqual(['_0', '_1', 'arg_1', 'arg_2'], get_placeholders('{{ 0 }} {{ 1 }} {{ arg_1 }} {{ arg_2 }}'))
 def test_get_placeholders_with_numbers(self):
     self.assertListEqual(['_0', '_1'], get_placeholders('{{ 0 }} {{ 1 }}'))
 def test_get_placeholders(self):
     self.assertListEqual(['arg_1', 'arg_2'], get_placeholders('{{ arg_1 }} {{ arg_2 }}'))