Skip to content

dvrkn/yaml-sorter-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YAML Sorter

This project is a Rust application that processes and sorts YAML files based on specific configurations.

Features

  • Sorting YAML Arrays: Sorts arrays in YAML files based on a specified key.
  • Sorting YAML Hashes: Sorts hashes in YAML files based on a predefined order and sorts remaining keys alphabetically.
  • Configurable: Uses a config.yaml file for customizable sorting rules.

Installation

To build and install the project, run the following command:

cargo build --release

The executable will be located in the target/release directory.

Usage

Command-line Interface

The application is run via the command line with the following syntax:

cargo run -- <action> <path>
  • <action>: The action to perform. For example, i for in-place processing.
  • <path>: The path to the YAML file to process.

Example:

cargo run -- i example.yaml

Configuration

The application uses a configuration file named config.yaml. The configuration file should be placed in the root directory of the project. This file specifies the order in which keys should be sorted and the key used for sorting arrays.

Example config.yaml:

preOrder:
  - key1
  - key2
sortKey: key_name

Example

Given the following example.yaml:

- age: 35
  name: Carol
- age: 30
  name: Alice
- age: 25
  name: Bob

Running the application with:

cargo run -- i example.yaml

And a config.yaml:

preOrder:
  - name
  - age
sortKey: name

Will produce the following sorted example.yaml:

- name: Alice
  age: 30
- name: Bob
  age: 25
- name: Carol
  age: 35

Running Tests

To run the tests, use the following command:

cargo test

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages