Skip to content

Commit 3abfa07

Browse files
committed
Add more documentation and example for transform utility
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 772548b commit 3abfa07

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

docs/source/reference.rst

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,115 @@ Details
617617
This option tells the tool to show all errors found.
618618
The default behavior will only show 'CRITICAL', 'ERROR', and 'WARNING'
619619
620+
--help-format
621+
-------------
622+
623+
.. code-block:: none
624+
625+
A transform configuration file is used to describe which transformations and
626+
validations to apply to a source CSV file. This is a simple text file using YAML
627+
format, using the same format as an .ABOUT file.
628+
629+
The attributes that can be set in a configuration file are:
630+
631+
* field_renamings:
632+
An optional map of source CSV or JSON field name to target CSV/JSON new field name that
633+
is used to rename CSV fields.
634+
635+
For instance with this configuration the fields "Directory/Location" will be
636+
renamed to "about_resource" and "foo" to "bar":
637+
field_renamings:
638+
about_resource : 'Directory/Location'
639+
bar : foo
640+
641+
The renaming is always applied first before other transforms and checks. All
642+
other field names referenced below are these that exist AFTER the renamings
643+
have been applied to the existing field names.
644+
645+
* required_fields:
646+
An optional list of required field names that must have a value, beyond the
647+
standard fields names. If a source CSV/JSON does not have such a field or a row is
648+
missing a value for a required field, an error is reported.
649+
650+
For instance with this configuration an error will be reported if the fields
651+
"name" and "version" are missing or if any row does not have a value set for
652+
these fields:
653+
required_fields:
654+
- name
655+
- version
656+
657+
* field_filters:
658+
An optional list of field names that should be kept in the transformed CSV/JSON. If
659+
this list is provided, all the fields from the source CSV/JSON that should be kept
660+
in the target CSV/JSON must be listed regardless of either standard or required
661+
fields. If this list is not provided, all source CSV/JSON fields are kept in the
662+
transformed target CSV/JSON.
663+
664+
For instance with this configuration the target CSV/JSON will only contains the "name"
665+
and "version" fields and no other field:
666+
field_filters:
667+
- name
668+
- version
669+
670+
* exclude_fields:
671+
An optional list of field names that should be excluded in the transformed CSV/JSON. If
672+
this list is provided, all the fields from the source CSV/JSON that should be excluded
673+
in the target CSV/JSON must be listed. Excluding standard or required fields will cause
674+
an error. If this list is not provided, all source CSV/JSON fields are kept in the
675+
transformed target CSV/JSON.
676+
677+
For instance with this configuration the target CSV/JSON will not contain the "type"
678+
and "temp" fields:
679+
exclude_fields:
680+
- type
681+
- temp
682+
683+
Example
684+
-------
685+
686+
fields renaming
687+
^^^^^^^^^^^^^^^
688+
689+
conf.txt
690+
""""""""
691+
692+
.. code-block:: none
693+
694+
field_renamings:
695+
about_resource : 'Directory / Filename'
696+
name : Component
697+
version: 'Confirmed Version'
698+
license_expression: 'Confirmed License Expression'
699+
700+
701+
input.csv
702+
"""""""""
703+
704+
+----------------------+-----------+--------------------+------------------------------+
705+
| Directory / Filename | Component | Confirmed Version | Confirmed License Expression |
706+
+======================+===========+====================+==============================+
707+
| /project/sample/ | sample | v 1.2.3 | apache-2.0 |
708+
+----------------------+-----------+--------------------+------------------------------+
709+
710+
711+
Command
712+
"""""""
713+
714+
.. code-block:: none
715+
716+
about transform -c conf.txt input.csv output.csv
717+
718+
The result output will look like the following:
719+
720+
output.csv
721+
""""""""""
722+
723+
+------------------+--------+---------+--------------------+
724+
| about_resource | name | version | license_expression |
725+
+==================+========+=========+====================+
726+
| /project/sample/ | sample | v 1.2.3 | apache-2.0 |
727+
+------------------+--------+---------+--------------------+
728+
620729
Special Notes
621730
-------------
622731
When using the field_filters configuration, all the standard required columns (about_resource and name) and the user defined required_fields need to be included.

0 commit comments

Comments
 (0)