Package: toml-sort
toml-sortA command line utility to sort and format your toml files.Read the latest documentation here:https://toml-sort.readthedocs.io/en/latest/Installationpipinstalltoml-sortMotivationThis library sorts TOML files, providing the following features:Sort tables and Arrays of Tables (AoT)Option to sort non-tables / non-AoT's, or notPreserve comments, where possibleStandardize whitespace and indentationI wrote this library/application because I couldn't find any "good" sorting utilities for TOML files. Now, I use this as part of my daily workflow. Hopefully it helps you too!Command line usageThis project can be used as either a command line utility or a Python library. Read the docs for an overview of its library capabilities. For command line usage, see below:$toml-sort--helpusage: toml-sort [-h] [--version] [-o OUTPUT] [-i] [-I] [-a] [--no-sort-tables] [--sort-table-keys][--sort-inline-tables] [--sort-inline-arrays] [--sort-first KEYS] [--no-header] [--no-comments][--no-header-comments] [--no-footer-comments] [--no-inline-comments] [--no-block-comments][--spaces-before-inline-comment {1,2,3,4}] [--spaces-indent-inline-array {2,4,6,8}][--trailing-comma-inline-array] [--check][F ...]Toml sort: a sorting utility for toml files.positional arguments:F                     filename(s) to be processed by toml-sort (default: -)optional arguments:-h, --help            show this help message and exit--version             display version information and exit-o OUTPUT, --output OUTPUToutput filepath (default: '-')-i, --in-place        overwrite the original input file with changes--check               silently check if an original file would be changed by the formattersort:change sorting behavior-I, --ignore-case     ignore case when sorting-a, --all             sort ALL keys. This implies sort table-keys, inline-tables and inline arrays. (default: onlysort non-inline 'tables and arrays of tables')--no-sort-tables      Disables the default behavior of sorting tables and arrays of tables by their header value.Setting this option will keep the order of tables in the toml file the same.--sort-table-keys     Sort the keys in tables and arrays of tables (excluding inline tables and arrays).--sort-inline-tables  Sort inline tables.--sort-inline-arrays  Sort inline arrays.--sort-first KEYS     Table keys that will be sorted first in the output. Multiple keys can be given separated by acomma.comments:exclude comments from output--no-header           Deprecated. See --no-header-comments--no-comments         remove all comments. Implies no header, footer, inline, or block comments--no-header-comments  remove a document's leading comments--no-footer-comments  remove a document's trailing comments--no-inline-comments  remove a document's inline comments--no-block-comments   remove a document's block commentsformatting:options to change output formatting--spaces-before-inline-comment {1,2,3,4}the number of spaces before an inline comment (default: 1)--spaces-indent-inline-array {2,4,6,8}the number of spaces to indent a multiline inline array (default: 2)--trailing-comma-inline-arrayadd trailing comma to the last item in a multiline inline arrayExamples:- **Stdin -> Stdout**: cat input.toml | toml-sort- **Disk -> Disk**: toml-sort -o output.toml input.toml- **Linting**: toml-sort --check input.toml input2.toml input3.toml- **Inplace Disk**: toml-sort --in-place input.toml input2.tomlReturn codes:- 0 : success.- 1 : errors were foundNotes:- You cannot redirect from a file to itself in Bash. POSIX shells processredirections first, then execute commands. --in-place exists for thisreasonConfiguration filetoml-sort can also be configured by using thepyproject.tomlfile. If the file exists and has atool.tomlsortsection, the configuration is used. If both command line arguments and the configuration are used, the options are merged. In the case of conflicts, the command line option is used.In short, the names are the same as on the command line (and have the same meaning), but-is replaced with_. Please note, that only the below options are supported:[tool.tomlsort]all=truein_place=trueno_comments=trueno_header_comments=trueno_footer_comments=trueno_inline_comments=trueno_block_comments=trueno_sort_tables=truesort_first=["key1","key2"]sort_table_keys=truesort_inline_tables=truesort_inline_arrays=truespaces_before_inline_comment=2spaces_indent_inline_array=4trailing_comma_inline_array=truecheck=trueignore_case=trueConfiguration OverridesThepyproject.tomlconfiguration file also supports configuration overrides, which are not available as command-line arguments. These overrides allow for fine-grained control of sort options for particular keys.Only the following options can be included in an override:[tool.tomlsort.overrides."path.to.key"]first=["key1","key2"]table_keys=trueinline_tables=trueinline_arrays=trueIn the example configuration,path.to.keyis the key to match. Keys are matched using thePython fnmatch function, so glob-style wildcards are supported.For instance, to disable sorting the table in the following TOML file:[servers.beta]ip="10.0.0.2"dc="eqdc10"country="中国"You can use any of the following overrides:# Overrides in own table[tool.tomlsort.overrides."servers.beta"]table_keys=false# Overrides in the tomlsort table[tool.tomlsort]overrides."servers.beta".table_keys=false# Override using a wildcard if config should be applied to all servers keys[tool.tomlsort]overrides."servers.*".table_keys=falseCommentsDue to the free form nature of comments, it is hard to include them in a sort in a generic way that will work for everyone.toml-sortdeals with four different types of comments. They are all enabled by default, but can be disabled using CLI switches, in which case comments of that type will be removed from the output.HeaderThe first comments in a document, that are followed by a blank line, are treated as a header, and will always remain at the top of the document. If there is no blank line, the comment will be treated as a block comment instead.# This is a header# it can be multiple lines, as long as it is followed with a blank line# it will always stay at the top of the sorted documenttitle="The example"FooterAny comments at the end of the document, after the last item in the toml, will be treated as a footer, and will always remain at the bottom of the document.title="The example"# this is a footer commentInlineInline comments are comments that are at the end of a line where the start of the line is a toml item.title="The example"# This is a inline commentBlockBlock comments, are any comments that are on their own line. These comments are treated asattachedto the item in the toml that is directly below them, not separated by whitespace. These comments can be multiple lines. Inline comments will appear in the sorted output above the item they were attached to in the input toml.# Comment attached to titletitle="The example"# This comment is an orphan because it# is separated from a-section by whitespace# This comment is attached to a-section# attached comments can be multiple lines[a-section]# This comment is attached to datedate="2019"OrphanOrphan comments are any comments that don't fall into the above categories, they will be removed from the output document.# Header comment# Orphan comment, not attached to any item# because there is whitespace before titletitle="The example"# This comment is an orphan because it# is separated from a-section by whitespace# This comment is attached to a-section[a-section]ExampleThe following example shows the input, and output, from the CLI with default options.Unformatted, unsorted input# My great TOML exampletitle="The example"[[a-section.hello]]ports=[8001,8001,8002]dob=1979-05-27T07:32:00Z# First class dates? Why not?# Attached to b-section[b-section]date="2018"name="Richard Stallman"[[a-section.hello]]ports=[80]#Attached to dobdob=1920-05-27T07:32:00Z# Another date![a-section]date="2019"name="Samuel Roeca"Formatted, sorted output# My great TOML exampletitle="The example"[a-section]date="2019"name="Samuel Roeca"[[a-section.hello]]ports=[8001,8001,8002]dob=1979-05-27T07:32:00Z# First class dates? Why not?[[a-section.hello]]ports=[80]# Attached to dobdob=1920-05-27T07:32:00Z# Another date!# Attached to b-section[b-section]date="2018"name="Richard Stallman"Local DevelopmentLocal development for this project is quite simple.DependenciesInstall the following tools manually.Poetry>=1.0GNU MakeRecommendedasdfSet up development environmentmakesetupRun TestsmaketestWritten bySamuel Roeca,samuel.roeca@gmail.com