Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Itemlists2 #24

Open
wants to merge 56 commits into
base: serde
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
21beef2
Deserializing unit structs implemented
tailhook Aug 15, 2017
db3f06f
Implements decoding mappings
tailhook Aug 15, 2017
e05b59d
Deserializes struct values
tailhook Aug 15, 2017
d679dfb
Implements deserialisation of enums
tailhook Aug 15, 2017
f67f519
Fixes final test
tailhook Aug 15, 2017
2b4c327
Merge branch 'serde': all original tests work
tailhook Aug 15, 2017
f84217f
vagga.yaml: upgrades rust and other things
tailhook Aug 15, 2017
21dae11
Removes old decode module (rustc_serialize) and fixes all tests
tailhook Aug 15, 2017
d50c2cd
Fixes tests for paths on windows
tailhook Aug 15, 2017
0671734
Adds `duration` and `regex` helper modules
tailhook Aug 16, 2017
32241e0
Fixes `deserialize_str` (fixes `regex` and `duration` modules)
tailhook Aug 16, 2017
b467588
Also test build without modules on travis
tailhook Aug 16, 2017
a314885
More options for booleans supported
tailhook Aug 16, 2017
6452d89
Renames json tests to transcode tests, fixes them
tailhook Aug 16, 2017
048896b
Shows path in errors again
tailhook Aug 16, 2017
62e883a
Hides `Error` type under a newtype
tailhook Aug 16, 2017
9e795bc
Exposed error constructors again (for use in include handlers)
tailhook Aug 16, 2017
237a0d4
Revert "More options for booleans supported"
tailhook Aug 17, 2017
2b630bf
Tweaks error messages
tailhook Aug 17, 2017
d1d88b6
Deserializing newtype structs is implemented
tailhook Aug 23, 2017
5dd2f3f
Fixes deserializing non-string mapping keys
tailhook Aug 23, 2017
db0ff2e
Upgrades rust to 1.20, adds packaging stuff
tailhook Sep 4, 2017
7d8c995
Version bumped to v0.3.0
tailhook Sep 4, 2017
b897eda
Custom errors for validators
anti-social Sep 20, 2017
1240b17
Refactor Error's constructors names
anti-social Sep 21, 2017
78bf7f2
Merge pull request #11 from anti-social/dev/custom-error
tailhook Sep 21, 2017
3e32f14
Adds "config" category to Cargo.toml
tailhook Sep 21, 2017
c2e792d
Converted README.rst -> README.md
tailhook Sep 21, 2017
d43953d
Version bumped to v0.3.1
tailhook Sep 21, 2017
8a6d8a3
vagga.yaml: Upgrade rust to v1.22.1, remove cargo-outdated from conta…
tailhook Dec 16, 2017
a767538
Eliminate few warnings
tailhook Dec 16, 2017
a412bcb
[breaking] Add support of IncludeSeq and IncludeMap
tailhook Dec 16, 2017
265511a
Allow tag and anchor in any order
tailhook Feb 9, 2018
9e75f86
Fix empty lines in literals when CRLF newlines are used
tailhook Apr 11, 2018
221cbdb
Better error reporting for nonimplemented things
tailhook Apr 11, 2018
c1d8464
[breaking] Remove regex module (use serde_regex), remove json module
tailhook May 25, 2018
9d247ed
Fix most warnings
tailhook May 25, 2018
ceb6b03
Remove unused attributes of Deserializer
tailhook May 25, 2018
7438579
Fix more warnings
tailhook May 25, 2018
3fbcb63
Remove duration parser (use humantime directly)
tailhook May 25, 2018
d1e7bdf
Implement debug for everything
tailhook May 25, 2018
bca4800
Make Error implement Send + Sync
tailhook May 25, 2018
cbdfe17
Fix duration test
tailhook May 25, 2018
1012d42
Version bumped to v0.4.0
tailhook May 27, 2018
3caa66d
Fix typo
tailhook May 31, 2018
1963992
vagga.yaml: upgrade containers
tailhook Jul 23, 2018
ea44229
Upgrade dependencies
tailhook Jul 23, 2018
91ad284
Error on tag or anchor before alias
tailhook Jul 23, 2018
a6dc2f6
Version bumped to v0.4.1
tailhook Jul 23, 2018
47f1489
Document there is more documentation
stappersg Jul 21, 2019
7167bfe
Bumped the year in sphinx-doc
tailhook Jul 21, 2019
f7b046d
Working example for lib.rs
stappersg Jul 22, 2019
4a431f8
Merge pull request #18 from stappersg/libRSexample
tailhook Jul 30, 2019
db76602
Merge pull request #16 from stappersg/bumpDocYear
tailhook Jul 30, 2019
1c0f06d
Merge pull request #13 from stappersg/moreDoc
tailhook Jul 30, 2019
a5f8179
Example with item lists
stappersg Aug 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
sudo: false
dist: trusty
language: rust
rust:
- stable
- beta
- nightly
script:
- cargo build --verbose
- cargo test --verbose

cache:
- cargo

before_cache:
- rm -r $TRAVIS_BUILD_DIR/target/debug

jobs:
include:
- os: linux
rust: stable
- os: linux
rust: beta
- os: linux
rust: nightly

# deploy
- stage: publish
os: linux
rust: stable
env:
# CARGO_TOKEN
- secure: "IPm2lHXAtXUY8pJtUMRV+jgLSCPKRJQyP3ax5aUhyaGlR83w4krEOcIpqQgu5a4rgw3SZUjDhxQMsRbzRZIehU+C3u2LTDpn0yycPnGmFRKVqnoS5dHdFMQ6IKLDZQK99MFZ/vMThipImnS9WFm2D1X/8XS31Mpn81Y7o54rIHk="
install: true
script: true

deploy:
- provider: script
script: 'cargo publish --verbose --token=$CARGO_TOKEN'
on:
tags: true
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
name = "quire"
description = "A YAML-based configuration parsing library"
license = "MIT/Apache-2.0"
readme = "README.rst"
readme = "README.md"
keywords = ["config", "yaml", "parser"]
homepage = "http://github.com/tailhook/rust-quire"
version = "0.2.3"
categories = ["config"]
version = "0.4.1"
authors = ["paul@colomiets.name"]

[dependencies]
rustc-serialize = "0.3"
quick-error = "1.0.0"
regex = "0.1.80"
humantime = "1.0.0"
num-traits = "0.1.36"
quick-error = "1.2.0"
num-traits = "0.2.5"
humannum = "0.1.0"
serde = "1.0.10"

[dev-dependencies]
serde_derive = "1.0.10"
serde_json = "1.0.2"
serde-transcode = "1.0.0"
serde-humantime = "0.1.1"
17 changes: 9 additions & 8 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
==========
Rust Quire
==========

:Status: Beta
*Status: Beta*


The ``rust-quire`` is a Rust_ port for quire_ configuration parsing library.
It also contains YAML_ parser (however, it tuned for configuration parsing
rather than generic YAML parser, e.g. it assumes YAML always fits memory).
The ``rust-quire`` is a [Rust][1] port for [quire][2] configuration parsing
library. It also contains [YAML][3] parser (however, it tuned for
configuration parsing rather than generic YAML parser, e.g. it assumes YAML
always fits memory).

See `doc/` for additional information.

.. _quire: http://github.com/tailhook/quire
.. _YAML: http://yaml.org
.. _Rust: http://rust-lang.org
[1]: http://github.com/tailhook/quire
[2]: http://yaml.org
[3]: http://rust-lang.org


License
Expand Down
15 changes: 15 additions & 0 deletions bulk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
minimum-bulk: v0.4.5

versions:

- file: Cargo.toml
block-start: ^\[package\]
block-end: ^\[.*\]
regex: ^version\s*=\s*"(\S+)"

- file: doc/conf.py
regex: ^version\s*=\s*'(\S+)'
partial-version: ^\d+\.\d+

- file: doc/conf.py
regex: ^release\s*=\s*'(\S+)'
11 changes: 11 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
doc/
====

In this directory documentation in [sphinx-doc][1] format.

Type `make html` to get HTML generated. Expect to get errors
when *sphinx-doc* is not installed on your system.

With `make` you get a list of possible output formats.

[1]: http://www.sphinx-doc.org/
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@

# General information about the project.
project = 'Quire'
copyright = '2013, Paul Colomiets'
copyright = '2013-2019, Paul Colomiets'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.0'
version = '0.4'
# The full version, including alpha/beta/rc tags.
release = '2.0-beta1'
release = '0.4.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
85 changes: 84 additions & 1 deletion doc/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ node that contains tag. For example:
.. code-block:: yaml

# config.yaml
items: !Include items.yaml
items: !*Include items.yaml

.. code-block:: yaml

Expand All @@ -209,6 +209,89 @@ Is equivalent of:
- banana


.. _include-seq:

Include Sequences of Files
--------------------------

The ``!*IncludeSeq`` tag includes files matched by glob as a sequence:

.. code-block:: yaml

items: !*IncludeSeq "fruits/*.yaml"

Can be parsed as:

.. code-block:: yaml

items:
- apple
- banana
- cherry

This depends on the exact application, but usually files returned by `glob`
are sorted in alphabetical order. All the power of globs is supported, so you
can do:

.. code-block:: yaml

items: !*IncludeSeq "files/**/*.yaml"

Another trick is merge multiple files, each with it's own set of keys into
a single one (see map-merge_ below):

.. code-block:: yaml

# file1.yaml
key1: 1
key2: 2
# file2.yaml
key3: 3
key4: 4
# main.yaml
<<: !*IncludeSeq "configs/*.yaml"

This results into the following config:

.. code-block:: yaml

key1: 1
key2: 2
key3: 3
key4: 4

Note: merging is not recursive, i.e. top level keys are considered as a whole,
even if they are dicts.


.. _include-map:

Include Mapping from Files
--------------------------

The ``!*IncludeMap`` tag works similarly to ``!*IncludeSeq`` but requires to
mark part of a name used as a key. For example:

.. code-block:: yaml

items: !*IncludeMap "fruits/(*).yaml"

Might result into the folowing:

.. code-block:: yaml

items:
apple: { color: orange }
banana: { color: yellow }
cherry: { color: red }

You can parenthesize any part as well as a whole path:

.. code-block:: yaml

files: !*IncludeMap "(**/*.yaml)"


.. _map-merge:

Merging Mappings
Expand Down
92 changes: 92 additions & 0 deletions examples/item_lists.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
extern crate quire;
#[macro_use] extern crate serde_derive;
use quire::{parse_config, Options};
use quire::validate::{Structure, Scalar, Sequence};
//e quire::validate::{Structure, Scalar, Sequence, Enum};
// TODO Marker_002 Validate against known vehicles


#[derive(Deserialize)]
#[allow(dead_code)]
struct Journey {
name: String,
year: String,
team: Members,
vehicles: Vehicles,
locations: Locations,
}

#[derive(Debug,Deserialize)]
struct Members(Vec<String>);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be something like

struct JourneyIter {
   team: Iterator;
   locations: Iterator;
   vehicles: Enumerator:
}

Or does rust-quire that already and have I no clue how to use it? ( Yes,I'm the person that opened #21, Item lists example :-/ )


/* TODO Marker_002 Validate against known vehicles
enum KnownVehicles {
Bobcat,
Jeep,
Landrover,
Unimog,
}
// TODO Marker_002 Validate against known vehicles
*/

#[derive(Deserialize)]
struct Vehicles(Vec<String>);
// TODO Marker_002 Validate against known vehicles

//#[derive(Deserialize)]
#[derive(Debug,Deserialize)]
struct Locations(Vec<String>);


// give it a method
// so we can create a iterator for it
#[allow(dead_code)]
impl Members {
fn new() -> Members {
Members(Vec::new())
}
}

// and implement IntoIterator
impl IntoIterator for Members {
type Item = String;
type IntoIter = ::std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

fn validator() -> Structure<'static> {
Structure::new()
.member("name", Scalar::new())
.member("year", Scalar::new())
.member("team", Sequence::new(Scalar::new()))
.member("vehicles", Sequence::new(Scalar::new()))
.member("locations", Sequence::new(Scalar::new()))
}

fn work(jrny: &Journey) {
println!("name is {}.", jrny.name);
println!("year is {}.", jrny.year);
/*
for tm in jrny.team {
println!("team member {}.", tm);
}
TODO make team iterable
*/
println!("team members {:?} DBG.", jrny.team); // TODO make team iterable
println!("{:?} DBG a.k.a. DeBuG", jrny.locations);
//
// TODO show more of what has been read from the YAML configuration
//
}

fn main() {
let jrny: Journey;
jrny = parse_config("examples/journey.yaml",
&validator(), &Options::default())
.expect("valid config");
work(&jrny)
}
23 changes: 23 additions & 0 deletions examples/journey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# journey.yaml
# "configuration" for item_lists

---
name: Voyage Voyage
year: 2020
team:
- Alice
- Bob
- Claire
- David
vehicles:
- Jeep
- Landrover
# Beware: TODO Marker_002 Validate against known vehicles
locations:
- Home
- Sweet
- Home

...
# l l
Loading