Add filter documentation (#87)

* Add filter documentation.

* Update no-unwanted-files sanity check.
This commit is contained in:
Felix Fontein 2022-04-30 16:40:59 +02:00 committed by GitHub
parent d56410b468
commit 02ecc0ca9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 152 additions and 0 deletions

26
plugins/filter/join.yml Normal file
View file

@ -0,0 +1,26 @@
DOCUMENTATION:
name: join
short_description: Join a list of arguments to a command
version_added: 2.0.0
description:
- Join and quotes a list of arguments to a command.
options:
_input:
description:
- A list of arguments to quote and join.
type: list
elements: string
required: true
author:
- Felix Fontein (@felixfontein)
EXAMPLES: |
- name: Join arguments for a RouterOS CLI command
ansible.builtin.set_fact:
arguments: "{{ ['foo=bar', 'comment=foo is bar'] | community.routeros.join }}"
# Should result in 'foo=bar comment="foo is bar"'
RETURN:
_value:
description: The joined and quoted result.
type: string

View file

@ -0,0 +1,36 @@
DOCUMENTATION:
name: list_to_dict
short_description: Convert a list of arguments to a dictionary
version_added: 2.0.0
description:
- Convert a list of arguments to a dictionary.
options:
_input:
description:
- A list of assignments. Can be the result of the C(community.routeros.split) filter.
type: list
elements: string
required: true
require_assignment:
description:
- Allows to accept arguments without values when set to C(false).
type: boolean
default: true
skip_empty_values:
description:
- Allows to skip arguments whose value is empty when set to C(true).
type: boolean
default: false
author:
- Felix Fontein (@felixfontein)
EXAMPLES: |
- name: Convert a list to a dictionary
ansible.builtin.set_fact:
dictionary: "{{ ['foo=bar', 'comment=foo is bar'] | community.routeros.list_to_dict }}"
# dictionary == {'foo': 'bar', 'comment': 'foo is bar'}
RETURN:
_value:
description: A dictionary representation of the input data.
type: dictionary

View file

@ -0,0 +1,25 @@
DOCUMENTATION:
name: quote_argument
short_description: Quote an argument
version_added: 2.0.0
description:
- Quote an argument.
options:
_input:
description:
- An argument to quote.
type: string
required: true
author:
- Felix Fontein (@felixfontein)
EXAMPLES: |
- name: Quote a RouterOS CLI command argument
ansible.builtin.set_fact:
quoted: "{{ 'comment=this is a "comment"' | community.routeros.quote_argument }}"
# Should result in 'comment="this is a \"comment\""'
RETURN:
_value:
description: The quoted argument.
type: string

View file

@ -0,0 +1,25 @@
DOCUMENTATION:
name: quote_argument_value
short_description: Quote an argument value
version_added: 2.0.0
description:
- Quote an argument value.
options:
_input:
description:
- An argument value to quote.
type: string
required: true
author:
- Felix Fontein (@felixfontein)
EXAMPLES: |
- name: Quote a RouterOS CLI command argument's value
ansible.builtin.set_fact:
quoted: "{{ 'this is a "comment"' | community.routeros.quote_argument_value }}"
# Should result in '"this is a \"comment\""'
RETURN:
_value:
description: The quoted argument value.
type: string

26
plugins/filter/split.yml Normal file
View file

@ -0,0 +1,26 @@
DOCUMENTATION:
name: split
short_description: Split a command into arguments
version_added: 2.0.0
description:
- Split a command into arguments.
options:
_input:
description:
- A command.
type: string
required: true
author:
- Felix Fontein (@felixfontein)
EXAMPLES: |
- name: Split command into list of arguments
ansible.builtin.set_fact:
argument_list: "{{ 'foo=bar comment="foo is bar" baz' | community.routeros.split }}"
# Should result in ['foo=bar', 'comment=foo is bar', 'baz']
RETURN:
_value:
description: The list of arguments.
type: list
elements: string

View file

@ -6,6 +6,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import os import os
import os.path
import sys import sys
@ -26,6 +27,11 @@ def main():
skip_directories = ( skip_directories = (
) )
yaml_directories = (
'plugins/test/',
'plugins/filter/',
)
for path in paths: for path in paths:
if path in skip_paths: if path in skip_paths:
continue continue
@ -33,8 +39,16 @@ def main():
if any(path.startswith(skip_directory) for skip_directory in skip_directories): if any(path.startswith(skip_directory) for skip_directory in skip_directories):
continue continue
if os.path.islink(path):
print('%s: is a symbolic link' % (path, ))
elif not os.path.isfile(path):
print('%s: is not a regular file' % (path, ))
ext = os.path.splitext(path)[1] ext = os.path.splitext(path)[1]
if ext in ('.yml', ) and any(path.startswith(yaml_directory) for yaml_directory in yaml_directories):
continue
if ext not in allowed_extensions: if ext not in allowed_extensions:
print('%s: extension must be one of: %s' % (path, ', '.join(allowed_extensions))) print('%s: extension must be one of: %s' % (path, ', '.join(allowed_extensions)))