Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mauro-balades/confy
💻 Configure projects effortlessly!
https://github.com/mauro-balades/confy
config configuration configuration-file init
Last synced: 19 days ago
JSON representation
💻 Configure projects effortlessly!
- Host: GitHub
- URL: https://github.com/mauro-balades/confy
- Owner: mauro-balades
- License: mit
- Created: 2024-05-02T13:46:39.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-06-19T19:34:03.000Z (8 months ago)
- Last Synced: 2025-01-13T19:44:06.734Z (24 days ago)
- Topics: config, configuration, configuration-file, init
- Language: C++
- Homepage:
- Size: 185 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**Confy**
Configure projects effortlessly! 💻This a project configuration file parser and system originally created for the [Snowball Programming Language](https://github.com/snowball-lang)!
[Issues](https://github.com/mauro-balades/confy/issues)
## Features
* Header only C++ library (bringing fast parsing times)
* Statically types (with syntax previously defined by the project executor)
* Enables efficient memory management through smart pointers
* Cross-platform compatibility for versatile deployment
* Comprehensive error handling for robust development## Show Me The Syntax!
```c++
auto root = confy::Interface::create({
{"project", confy::Type::Object({
{"name", confy::Type::String},
{"version", confy::Type::String},
{"authors", confy::Type::Array(confy::Type::String)},
{"description", confy::Type::String},
})},
});auto result = confy::parse_file(root, "./project.confy");
// { errors: {}, root: ... }
```Will be able to parse:
```conf
# haha, you cant see me!project {
name = "MyLib"
version = "1.0.0"
author = ["Your Name"]
description = "A project created with Confy!"
}
```# Data Types
### Object
* A set of values of values that can be accessed by name
```c++
Types::Object({
{"name": Type},
...
});
``````js
myObject {
name = type
}
```### Array
* A set of values with the same type that can contain an infinite ammount of elements (from 0 to infinity)
```c++
Types::Array(Type);
``````js
myArray = ["Hello", "Adios", "Ñog"]
```### String
* An array of characters (it's just a string)
```c++
Types::String;
``````js
myName = "mauro!"
```### Number
* A number from -inf to inf that can contain decimal places (represented as a double in the backend)
```c++
Types::Number;
``````js
myNumber = 25
```## Utility Types
* Utility types are used to validate the given data.
* To enable the utility classes, define the `CONFY_USE_UTILS` macro before including `confy.hpp`
* If the validation returns an error, it will be thrown and the parsing will fail### MinNumType
* A number that must be bigger than `N1`
```c++
MinNumType<10>::create();
``````js
myNumber = 12
```### MaxNumType
* A number that must be less than `N1`
```c++
MaxNumType<10>::create();
``````js
myNumber 6
```### RangeNumType
* A number that must be bigger than `N1`and less than `N2`
```c++
RangeNumType<10, 20>::create();
``````js
myNumber = 12
```### MinStrType
* The parsed string's length must be bigger than `S1`
```c++
MinStrType<3>::create();
``````js
myString = "hello there"
```### StrRegexType
* The parsed string's must satisfy the given regex
```c++
StrRegexType::create("*");
``````js
myString = "I dont know how regex works"
```### Custom Validation Types
* To create your own validation type, create a new class inheriting from a `primitive type` (like `NumType` or `StringType`).
* Override the `validate` method where it's value may depend from which type is being inherited from.Example of a class that only accepts if a string starts with "hello".
```c++
class MyCustomType : public confy::StringType {
public:
// Validate takes a `double` if it inherits from `confy::NumType`!
std::optional validate(const std::string& value) const override {
if (s.rfind("hello", 0) == 0) {
return std::nullopt;
}
return "String must start with 'hello'!";
}// Optional but it's nice to have a generator function
static std::shared_ptr create() {
return std::make_shared();
}
}
```Usage
```c++
{"myStr": MyCustomType::create()}
```This will work as (ignore the duplicate name error):
```py
myStr = "hello world"myStr = "hello mauro"
# error!
myStr = "goodbye :("
```