Compare commits

..

44 Commits
0.3.0 ... main

Author SHA1 Message Date
Bauke 57b6c64ea0
Version 1.1.6! 2024-01-21 13:59:35 +01:00
Bauke 7c20a44619
Update license years. 2024-01-21 13:59:24 +01:00
Bauke 495e6ac048
Add the Development section. 2024-01-21 13:58:36 +01:00
Bauke f9bfe86ad6
Redo the cargo-make configuration to make use of default tasks. 2024-01-21 13:50:11 +01:00
Bauke 3bf315829a
Update all dependencies. 2024-01-21 13:48:27 +01:00
Bauke 0a03826fd2
Fix Clippy issues. 2024-01-21 13:44:26 +01:00
Bauke b0893af002
Switch the resolver. 2024-01-21 13:42:23 +01:00
Bauke d7278ba3a2
Add Nix flake and direnv files. 2024-01-21 13:41:41 +01:00
Bauke 7545039bec
Version 1.1.5! 2022-10-02 22:10:29 +02:00
Bauke 49969b307a
Update RSS example. 2022-10-02 21:54:15 +02:00
Bauke 8b450cc724
Clean up documentation. 2022-10-02 21:30:15 +02:00
Bauke 2ebc218149
Forbid unsafe code and add documentation warnings. 2022-10-02 16:12:12 +02:00
Bauke 521a9bbd1a
Update Cargo.toml metadata info. 2022-10-01 01:06:29 +02:00
Bauke 3a001d1326
Update edition and dependencies. 2022-10-01 01:03:47 +02:00
Bauke fc2503e752
Add Eq derives. 2022-10-01 01:00:34 +02:00
Bauke 243750ff5f
Rewrite CLI tests using insta and test_case. 2022-10-01 00:55:12 +02:00
Bauke 9db7f4f1b2
Update CLI dependencies, rewrite with Clap's Derive API. 2022-10-01 00:09:13 +02:00
Bauke 3a466adedc
Update license year and email. 2022-09-30 23:46:53 +02:00
Bauke b32e45d058
Update gitignore and move coverage directory. 2022-09-30 23:36:21 +02:00
Bauke dda3e2debc
Rewrite readme. 2022-09-30 23:34:20 +02:00
Bauke 3442351223
Version 1.1.4. 2022-07-20 14:25:56 +02:00
Bauke b4fadea55d
Run cargo fmt. 2022-07-20 14:14:44 +02:00
Kevin Cox 34677a5fa1
Switch to hard-xml. (#4)
strong-xml is unmaintained and this fork includes a fix to a self-closing element causing a parse error.

This also fixes a build-time warning with the strong-xml derive macro.
2022-07-19 13:47:46 +02:00
Bauke 75eb03b23f
Version 1.1.3 2021-09-27 19:28:36 +02:00
Bauke a39b0b8db8
Version 1.1.2 2021-09-27 19:24:12 +02:00
Bauke 1ae347f2ef
Remove unused imports from doc examples. 2021-09-27 13:49:08 +02:00
Bauke 4f285142d8
Remove the Regex dependency.
This isn't really necessary if we're checking against
a list of valid versions.
2021-09-27 13:37:43 +02:00
Bauke 9ef1bf37ef
Add cargo-make tasks. 2021-09-27 12:36:57 +02:00
Bauke c146776e8b
Add more tests. 2021-09-27 12:23:50 +02:00
Bauke 40e9e785b9
Fix a Clippy warning. 2021-09-27 12:07:31 +02:00
Bauke fab193f2dd
Clean up and update the documentation. 2021-09-27 12:06:22 +02:00
Bauke 00fc02f7a0
Update all dependencies. 2021-09-26 22:21:24 +02:00
Bauke d0b85869e3
Remove GitHub CI stuff. 2021-09-26 22:14:50 +02:00
Bauke f7d820e217
Version 1.1.1 2021-07-05 23:05:05 +02:00
Bauke 53618bfd5f
Update license year and include files in publishes crates. 2021-07-05 23:01:32 +02:00
Bauke 8f3109d719
Version 1.1.0 2021-03-23 13:05:30 +01:00
Bauke e8006bff09
Fix some things and do some cleanup. 2021-03-23 13:02:16 +01:00
SirWindfield 88d96dea73 feat: add convenience methods for (de)serialization
The commit adds a from_reader and to_writer method implementation to
make it easier to work with IO streams.

Additionally, I have deprecated the `new` and `to_xml` functions in
favor of functions that match the naming scheme of serde crates more
closely: `from_str` and `to_string`.
2021-03-22 22:31:59 +01:00
Bauke d50c5ca4b6
Version 1.0.1
Publishing failed for strong-xml 0.6.1, this just bumps it to 0.6.2 to fix that.
2021-03-22 14:04:25 +01:00
Bauke a93cf7abd6
Version 1.0.0 2021-03-22 12:50:59 +01:00
SirWindfield 312627e298
feat(api)!: add distinct error type (#1)
* feat(api)!: add distinct error type

The commit adds an `Error` enum to the public API of the opml crate to
make it easier to reason about what went wrong during OPML
parsing/writing.
2021-03-22 12:41:11 +01:00
Bauke f1a4f57ec2
Restore rustfmt.toml and apply changes. 2020-08-29 16:46:54 +02:00
Bauke a402a632f4
Add a basic Rust CI GitHub workflow. 2020-08-29 16:43:15 +02:00
Bauke 737fdb70d8
Actually point to the license. 2020-08-28 13:42:28 +02:00
43 changed files with 1673 additions and 706 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake

7
.gitignore vendored
View File

@ -1,5 +1,4 @@
# Compiled files and executables.
.direnv/
coverage/
debug/
target/
# Backup files generated by rustfmt.
**/*.rs.bk

486
Cargo.lock generated
View File

@ -1,29 +1,63 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.13"
name = "anstream"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
dependencies = [
"memchr",
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"winapi",
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "assert_cmd"
version = "1.0.1"
version = "2.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c88b9ca26f9c16ec830350d309397e74ee9abdfd8eb1f71cb6ecc71a3fc818da"
checksum = "00ad3f3a942eee60335ab4342358c161ee296829e0d16ff42fc1d6cb07815467"
dependencies = [
"anstyle",
"bstr",
"doc-comment",
"predicates",
"predicates-core",
@ -32,42 +66,91 @@ dependencies = [
]
[[package]]
name = "atty"
version = "0.2.14"
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc"
dependencies = [
"hermit-abi",
"libc",
"winapi",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "bitflags"
version = "1.2.1"
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
"clap_builder",
"clap_derive",
]
[[package]]
name = "difference"
version = "2.0.0"
name = "clap_builder"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "console"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"windows-sys",
]
[[package]]
name = "difflib"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
[[package]]
name = "doc-comment"
@ -76,25 +159,66 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "hermit-abi"
version = "0.1.15"
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "hard-xml"
version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fafc2bcb74049535eb6fab49eb20164a427867a9e809516ef95a98e961164432"
dependencies = [
"libc",
"hard-xml-derive",
"jetscii",
"lazy_static",
"memchr",
"xmlparser",
]
[[package]]
name = "hard-xml-derive"
version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a345b327da51b997c94f841d9db6b2d292c7632713bd8a1b8b191e8b819df7"
dependencies = [
"bitflags",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "insta"
version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d64600be34b2fcfc267740a243fa7744441bb4947a619ac4e5bb6507f35fbfc"
dependencies = [
"console",
"lazy_static",
"linked-hash-map",
"similar",
"yaml-rust",
]
[[package]]
name = "itoa"
version = "0.4.6"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "jetscii"
version = "0.4.4"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f25cca2463cb19dbb1061eb3bd38a8b5e4ce1cc5a5a9fc0e02de486d92b9b05"
checksum = "47f142fe24a9c9944451e8349de0a56af5f3e7226dc46f3ed4d4ecc0b85af75e"
[[package]]
name = "lazy_static"
@ -104,129 +228,126 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.76"
version = "0.2.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3"
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "memchr"
version = "2.3.3"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "opml"
version = "0.3.0"
version = "1.1.6"
dependencies = [
"regex",
"hard-xml",
"serde",
"strong-xml",
"thiserror",
]
[[package]]
name = "opml_cli"
version = "0.3.0"
version = "1.1.6"
dependencies = [
"assert_cmd",
"clap",
"insta",
"opml",
"serde",
"serde_json",
"test-case",
]
[[package]]
name = "predicates"
version = "1.0.5"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96bfead12e90dccead362d62bb2c90a5f6fc4584963645bc7f71a735e0b0735a"
checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8"
dependencies = [
"difference",
"anstyle",
"difflib",
"predicates-core",
]
[[package]]
name = "predicates-core"
version = "1.0.0"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174"
[[package]]
name = "predicates-tree"
version = "1.0.0"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf"
dependencies = [
"predicates-core",
"treeline",
"termtree",
]
[[package]]
name = "proc-macro2"
version = "1.0.19"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.7"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.3.9"
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
[[package]]
name = "ryu"
version = "1.0.5"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "serde"
version = "1.0.115"
version = "1.0.195"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.115"
version = "1.0.195"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.48",
]
[[package]]
name = "serde_json"
version = "1.0.57"
version = "1.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4"
dependencies = [
"itoa",
"ryu",
@ -234,87 +355,109 @@ dependencies = [
]
[[package]]
name = "strong-xml"
version = "0.6.0"
name = "similar"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee06e7e5baf4508dea83506a83fcc5b80a404d4c0e9c473c9a4b38b802af3a07"
dependencies = [
"jetscii",
"lazy_static",
"memchr",
"strong-xml-derive",
"xmlparser",
]
[[package]]
name = "strong-xml-derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2e4e25fb64e61f55d495134d9e5ac68b1fa4bb2855b5a5b53857b9460e2bfde"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21"
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.39"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "textwrap"
version = "0.11.0"
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"unicode-width",
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.0.1"
name = "termtree"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
[[package]]
name = "test-case"
version = "3.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb2550dd13afcd286853192af8601920d959b14c401fcece38071d53bf0768a8"
dependencies = [
"lazy_static",
"test-case-macros",
]
[[package]]
name = "treeline"
version = "0.1.0"
name = "test-case-core"
version = "3.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
checksum = "adcb7fd841cd518e279be3d5a3eb0636409487998a4aff22f3de87b81e88384f"
dependencies = [
"cfg-if",
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
name = "test-case-macros"
version = "3.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"test-case-core",
]
[[package]]
name = "unicode-xid"
name = "thiserror"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "wait-timeout"
@ -326,29 +469,82 @@ dependencies = [
]
[[package]]
name = "winapi"
version = "0.3.9"
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
"windows-targets",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
name = "windows-targets"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "xmlparser"
version = "0.13.2"
version = "0.13.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52613e655f6f11f63c0fe7d1c3b5ef69e44d96df9b65dab296b441ed0e1125f5"
checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

View File

@ -5,3 +5,4 @@ members = [
"opml_api",
"opml_cli"
]
resolver = "2"

View File

@ -1,6 +1,6 @@
The MIT License
Copyright (c) 2020 Holllo <helllo@holllo.cc>
Copyright (c) 2020-2024 Holllo <helllo@holllo.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

31
Makefile.toml Normal file
View File

@ -0,0 +1,31 @@
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
# Do a full check of everything.
[tasks.complete-check]
dependencies = [
"clean",
"format",
"check",
"clippy",
"test",
"code-coverage",
"docs",
"build",
"audit-flow",
"outdated-flow"
]
# Run cargo-tarpaulin and output the test coverage.
[tasks.code-coverage]
workspace = false
command = "cargo"
args = [
"tarpaulin",
"--exclude-files=target/*",
"--out=html",
"--output-dir=coverage",
"--skip-clean",
"--target-dir=target/tarpaulin",
"--workspace"
]

View File

@ -1,21 +1,31 @@
# OPML
# OPML 📄
> An OPML parser for Rust and the command-line.
> **OPML library for Rust & standalone CLI.**
## API
For the API documentation, see [docs.rs](https://docs.rs/opml).
For API documentation and examples see [docs.rs](https://docs.rs/opml).
## CLI
To install the OPML command-line parser, run `cargo install opml_cli` or download a precompiled executable directly from [the Releases page](https://github.com/Holllo/opml/releases/latest).
### Cargo
Then run `opml --help` to see all the available options.
With a working [Rust and Cargo](https://www.rust-lang.org/learn/get-started) installation, you can install the OPML CLI from [Crates.io](https://crates.io/crates/opml_cli).
```
cargo install opml_cli
```
### Binaries
Precompiled `x86_64-unknown-linux-gnu` binaries are available on the [Releases page](https://git.bauke.xyz/Holllo/opml/releases).
## Development
With [Nix flakes](https://nixos.wiki/wiki/Flakes) and [direnv](https://direnv.net/) installed and enabled, all the required dependencies are automatically loaded from [`shell.nix`](./shell.nix). Then [cargo-make](https://sagiegurari.github.io/cargo-make/) can be used to build, deploy and lint the code. The available tasks are all described in the [`Makefile.toml`](Makefile.toml) configuration.
## License
Both the API and command-line parser are licensed under either of [Apache License, Version 2.0](https://github.com/Holllo/opml/blob/main/LICENSE-Apache) or [MIT license](https://github.com/Holllo/opml/blob/main/LICENSE-MIT) at your option.
Distributed under the [Apache License 2.0](https://spdx.org/licenses/Apache-2.0.html) and [MIT](https://spdx.org/licenses/MIT.html) licenses, see [LICENSE-Apache](https://git.bauke.xyz/Holllo/opml/src/branch/main/LICENSE-Apache) and [LICENSE-MIT](https://git.bauke.xyz/Holllo/opml/src/branch/main/LICENSE-MIT) for more information.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in either crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
The samples [located in `opml_api/tests/spec_samples`](https://github.com/Holllo/opml/tree/main/opml_api/tests/spec_samples) were [taken from the OPML 2.0 spec](http://dev.opml.org/spec2.html#examples) and are subject to [their own license](https://github.com/Holllo/opml/tree/main/opml_api/tests/spec_samples).
The samples located in `opml_api/tests/spec_samples`) were [taken from the OPML 2.0 spec](http://dev.opml.org/spec2.html#examples) and are subject to [their own license](https://git.bauke.xyz/Holllo/opml/src/branch/main/opml_api/tests/spec_samples/LICENSE).

128
flake.lock Normal file
View File

@ -0,0 +1,128 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1705697961,
"narHash": "sha256-XepT3WS516evSFYkme3GrcI3+7uwXHqtHbip+t24J7E=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e5d1c87f5813afde2dda384ac807c57a105721cc",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1705803528,
"narHash": "sha256-nChqKQPRXxmGBEkHse39LjNpkNKk4U1xPQ4a4oYlUdw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "bd7e8f4e122e11c934a576abc04327764f9bf19b",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
flake.nix Normal file
View File

@ -0,0 +1,17 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

View File

@ -2,19 +2,22 @@
[package]
name = "opml"
description = "An OPML parser for Rust."
authors = ["Holllo <helllo@holllo.cc>"]
version = "0.3.0"
description = "OPML library for Rust."
repository = "https://git.bauke.xyz/Holllo/opml"
license = "MIT OR Apache-2.0"
repository = "https://github.com/Holllo/opml"
version = "1.1.6"
authors = ["Holllo <helllo@holllo.org>"]
edition = "2021"
readme = "../README.md"
edition = "2018"
keywords = ["xml", "opml"]
[lib]
path = "source/lib.rs"
[dependencies]
regex = "1.3"
serde = { version = "1.0", features = ["derive"] }
strong-xml = "0.6"
hard-xml = "1.34.0"
thiserror = "1.0.56"
[dependencies.serde]
version = "1.0.195"
features = ["derive"]

202
opml_api/LICENSE-Apache Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

21
opml_api/LICENSE-MIT Normal file
View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2020-2024 Holllo <helllo@holllo.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,27 +1,31 @@
use std::error::Error;
use std::fs;
use opml::OPML;
fn main() -> Result<(), Box<dyn Error>> {
let xml = fs::read_to_string("examples/opml_samples/rust_feeds.opml")?;
const SAMPLE: &str = r#"<opml version="2.0">
<head>
<title>Rust Feeds</title>
</head>
<body>
<outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml" />
<outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml" />
</body>
</opml>"#;
let subscriptions = OPML::new(&xml)?;
let head = subscriptions.head.unwrap();
let title = head.title.unwrap();
/// Run this example using `cargo run --example rss`.
///
/// Output:
/// Rust Feeds
/// ──────────
/// Rust Blog https://blog.rust-lang.org/feed.xml
/// Inside Rust https://blog.rust-lang.org/inside-rust/feed.xml
fn main() {
let subscriptions = OPML::from_str(SAMPLE).unwrap();
println!(" {}", title);
println!(" {}", "".repeat(title.len()));
for outline in subscriptions.body.outlines {
println!(" {}\t{}", outline.text, outline.xml_url.unwrap());
if let Some(title) = subscriptions.head.and_then(|head| head.title) {
println!("{}", title);
println!("{}", "-".repeat(title.len()));
}
Ok(())
for outline in subscriptions.body.outlines {
println!("{}\t{}", outline.text, outline.xml_url.unwrap());
}
}
// Output:
// Rust Feeds
// ──────────
// Rust Blog https://blog.rust-lang.org/feed.xml
// Inside Rust https://blog.rust-lang.org/inside-rust/feed.xml

View File

@ -1,352 +1,441 @@
//! This crate provides an API to parse and construct
//! [OPML documents](http://dev.opml.org/spec2.html) to and from regular Rust
//! structs.
//! This crate provides an API to parse and create [OPML documents].
//!
//! ## Getting Started
//! [OPML documents]: http://opml.org/spec2.opml
//!
//! ### Parsing
//! ## Parsing
//!
//! Parsing XML into [an OPML struct](struct.OPML.html) can be done with
//! [`OPML::new()`](struct.OPML.html#method.new). Resulting in an error if the
//! XML can't be parsed, if the included OPML version is not supported
//! (currently all OPML versions (1.0, 1.1 and 2.0) are supported) or if the
//! [Body](struct.Body.html) element contains no child
//! [Outline](struct.Outline.html) elements,
//! [as per the spec](http://dev.opml.org/spec2.html#whatIsALtbodygt).
//! To parse an OPML document use [`OPML::from_str`] or [`OPML::from_reader`].
//!
//! Parsing will result in an error if:
//! * the XML is malformed,
//! * the included OPML version is not supported (currently all OPML versions
//! (1.0, 1.1 and 2.0) are supported) or,
//! * if the [`Body`] element contains no child [`Outline`] elements,
//! [as per the spec].
//!
//! [as per the spec]: http://opml.org/spec2.opml#1629042198000
//!
//! ```rust
//! use opml::{OPML, Outline};
//! use opml::OPML;
//!
//! let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
//! let parsed = OPML::new(xml).unwrap();
//! let document = OPML::from_str(xml).unwrap();
//!
//! let mut expected = OPML::default();
//! expected.body.outlines.push(Outline {
//! text: "Outline".to_string(),
//! ..Outline::default()
//! });
//!
//! println!("{:#?}", parsed);
//! assert_eq!(parsed, expected);
//! assert_eq!(document.version, "2.0");
//! ```
//!
//! ### Constructing
//! ## Creating
//!
//! Constructing OPMLs is very easy as all you have to do is instantiate the
//! [OPML struct](struct.OPML.html) with
//! [`OPML::default()`](struct.OPML.html#method.default), add anything wanted
//! and then call [`OPML::to_xml()`](struct.OPML.html#method.to_xml) to return
//! the XML as a string.
//!
//! ```rust
//! use opml::{Head, OPML};
//!
//! let mut opml = OPML::default();
//! opml.head = Some(Head {
//! title: Some("Rust Feeds".to_string()),
//! ..Head::default()
//! });
//! opml
//! .add_feed("Rust Blog", "https://blog.rust-lang.org/feed.xml")
//! .add_feed(
//! "Inside Rust",
//! "https://blog.rust-lang.org/inside-rust/feed.xml",
//! );
//!
//! let xml = opml.to_xml().unwrap();
//! let expected = r#"<opml version="2.0"><head><title>Rust Feeds</title></head><body><outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml"/><outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml"/></body></opml>"#;
//! println!("{}", xml);
//! assert_eq!(xml, expected);
//! ```
//! To create an OPML document from scratch, use [`OPML::default()`] or the good
//! old `OPML { /* ... */ }` syntax.
use regex::Regex;
#![forbid(unsafe_code)]
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
use hard_xml::{XmlRead, XmlWrite};
use serde::{Deserialize, Serialize};
use strong_xml::{XmlError, XmlRead, XmlWrite};
use thiserror::Error;
/// The top-level [OPML](struct.OPML.html) element.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Serialize, Deserialize)]
/// All possible errors.
#[derive(Debug, Error)]
pub enum Error {
/// [From the spec], "a `<body>` contains one or more `<outline>` elements".
///
/// [From the spec]: http://opml.org/spec2.opml#1629042198000
#[error("OPML body has no <outline> elements")]
BodyHasNoOutlines,
/// Wrapper for [`std::io::Error`].
#[error("Failed to read file")]
IoError(#[from] std::io::Error),
/// The version string in the XML is not supported.
#[error("Unsupported OPML version: {0:?}")]
UnsupportedVersion(String),
/// The input string is not valid XML.
#[error("Failed to process XML file")]
XmlError(#[from] hard_xml::XmlError),
}
/// The top-level [`OPML`] element.
#[derive(
XmlWrite, XmlRead, PartialEq, Eq, Debug, Clone, Serialize, Deserialize,
)]
#[xml(tag = "opml")]
pub struct OPML {
/// The version attribute from the element, valid values are `1.0`, `1.1` and `2.0`.
#[xml(attr = "version")]
pub version: String,
/// The version attribute from the element, valid values are `1.0`, `1.1` and
/// `2.0`.
#[xml(attr = "version")]
pub version: String,
/// The [Head](struct.Head.html) child element. Contains the metadata of the OPML document.
#[xml(child = "head")]
pub head: Option<Head>,
/// The [`Head`] child element. Contains the metadata of the OPML document.
#[xml(child = "head")]
pub head: Option<Head>,
/// The [Body](struct.Body.html) child element. Contains all the [Outlines](struct.Outline.html).
#[xml(child = "body")]
pub body: Body,
/// The [`Body`] child element. Contains all the [`Outline`] elements.
#[xml(child = "body")]
pub body: Body,
}
impl OPML {
/// Parses an OPML document.
///
/// # Example
///
/// ```rust
/// use opml::{OPML, Outline};
///
/// let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
/// let parsed = OPML::new(xml).unwrap();
///
/// let mut expected = OPML::default();
/// expected.body.outlines.push(Outline {
/// text: "Outline".to_string(),
/// ..Outline::default()
/// });
///
/// assert_eq!(parsed, expected);
/// ```
pub fn new(xml: &str) -> Result<Self, String> {
let opml: Result<OPML, XmlError> = OPML::from_str(xml);
/// Deprecated, use [`OPML::from_str`] instead.
#[deprecated(note = "Use from_str instead", since = "1.1.0")]
pub fn new(xml: &str) -> Result<Self, Error> {
Self::from_str(xml).map_err(Into::into)
}
let opml = match opml {
Ok(value) => value,
Err(err) => return Err(format!("XML parsing error: {:#?}", err)),
};
/// Parses an OPML document.
///
/// # Example
///
/// ```rust
/// use opml::{OPML, Outline};
///
/// let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
/// let document = OPML::from_str(xml).unwrap();
///
/// let mut expected = OPML::default();
/// expected.body.outlines.push(Outline {
/// text: "Outline".to_string(),
/// ..Outline::default()
/// });
///
/// assert_eq!(document, expected);
/// ```
#[allow(clippy::should_implement_trait)]
pub fn from_str(xml: &str) -> Result<Self, Error> {
let opml = <OPML as XmlRead>::from_str(xml)?;
let version = &opml.version;
// SPEC: The version attribute is a version string, of the form, x.y, where
// x and y are both numeric strings.
let valid_versions = ["1.0", "1.1", "2.0"];
// SPEC: The version attribute is a version string, of the form, x.y, where x and y are both numeric strings.
let valid_version_regex = Regex::new(r"^\d+\.\d+$").unwrap();
let valid_versions = vec!["1.0", "1.1", "2.0"];
if !valid_version_regex.is_match(version) || !valid_versions.contains(&version.as_str()) {
return Err(format!(
"Unsupported OPML version detected: {}",
opml.version
));
}
// SPEC: A `<body>` contains one or more `<outline>` elements.
if opml.body.outlines.is_empty() {
return Err("OPML body has no outlines.".to_string());
}
Ok(opml)
if !valid_versions.contains(&opml.version.as_str()) {
return Err(Error::UnsupportedVersion(opml.version));
}
/// Helper function to add an [Outline](struct.Outline.html) element with `text` and `xml_url` attributes to the [Body](struct.Body.html). Useful for creating feed lists quickly. This function [also exists on the Outline struct](struct.Outline.html#method.add_feed) to create grouped lists easily.
///
/// # Example
///
/// ```rust
/// use opml::{OPML, Outline};
///
/// let mut opml = OPML::default();
/// opml.add_feed("Feed Name", "https://example.com/");
/// let added_feed = opml.body.outlines.first().unwrap();
///
/// let expected_feed = &Outline {
/// text: "Feed Name".to_string(),
/// xml_url: Some("https://example.com/".to_string()),
/// ..Outline::default()
/// };
///
/// assert_eq!(added_feed, expected_feed);
/// ```
pub fn add_feed(&mut self, text: &str, url: &str) -> &mut Self {
self.body.outlines.push(Outline {
text: text.to_string(),
xml_url: Some(url.to_string()),
..Outline::default()
});
self
// SPEC: A `<body>` contains one or more `<outline>` elements.
if opml.body.outlines.is_empty() {
return Err(Error::BodyHasNoOutlines);
}
/// Converts the struct to an XML document.
///
/// # Example
///
/// ```rust
/// use opml::OPML;
///
/// let opml = OPML::default();
/// let xml = opml.to_xml().unwrap();
///
/// let expected = r#"<opml version="2.0"><head/><body/></opml>"#;
/// assert_eq!(xml, expected);
/// ```
pub fn to_xml(&self) -> Result<String, String> {
let result: Result<String, XmlError> = self.to_string();
Ok(opml)
}
match result {
Ok(value) => Ok(value),
Err(err) => Err(format!("XML writing error: {:#?}", err)),
}
}
/// Parses an OPML document from a reader.
///
/// # Example
///
/// ```rust,no_run
/// use opml::OPML;
///
/// let mut file = std::fs::File::open("file.opml").unwrap();
/// let document = OPML::from_reader(&mut file).unwrap();
/// ```
pub fn from_reader<R>(reader: &mut R) -> Result<Self, Error>
where
R: std::io::Read,
{
let mut s = String::new();
reader.read_to_string(&mut s)?;
Self::from_str(&s).map_err(Into::into)
}
/// Helper function to add an [`Outline`] element with `text` and `xml_url`
/// attributes to the [`Body`]. Useful for creating feed lists quickly.
/// This function also exists as [`Outline::add_feed`] for grouped lists.
///
/// # Example
///
/// ```rust
/// use opml::{OPML, Outline};
///
/// let mut opml = OPML::default();
/// opml.add_feed("Feed Name", "https://example.com/");
/// let added_feed = opml.body.outlines.first().unwrap();
///
/// let expected_feed = &Outline {
/// text: "Feed Name".to_string(),
/// xml_url: Some("https://example.com/".to_string()),
/// ..Outline::default()
/// };
///
/// assert_eq!(added_feed, expected_feed);
/// ```
pub fn add_feed(&mut self, text: &str, url: &str) -> &mut Self {
self.body.outlines.push(Outline {
text: text.to_string(),
xml_url: Some(url.to_string()),
..Outline::default()
});
self
}
/// Deprecated, use [`OPML::to_string`] instead.
#[deprecated(note = "Use to_string instead", since = "1.1.0")]
pub fn to_xml(&self) -> Result<String, Error> {
self.to_string()
}
/// Converts the struct to an XML document.
///
/// # Example
///
/// ```rust
/// use opml::OPML;
///
/// let opml = OPML::default();
/// let xml = opml.to_string().unwrap();
///
/// let expected = r#"<opml version="2.0"><head/><body/></opml>"#;
/// assert_eq!(xml, expected);
/// ```
pub fn to_string(&self) -> Result<String, Error> {
Ok(XmlWrite::to_string(self)?)
}
/// Converts the struct to an XML document and writes it using the writer.
///
/// # Example
///
/// ```rust,no_run
/// use opml::OPML;
///
/// let opml = OPML::default();
/// let mut file = std::fs::File::create("file.opml").unwrap();
/// let xml = opml.to_writer(&mut file).unwrap();
/// ```
pub fn to_writer<W>(&self, writer: &mut W) -> Result<(), Error>
where
W: std::io::Write,
{
let xml_string = self.to_string()?;
writer.write_all(xml_string.as_bytes())?;
Ok(())
}
}
impl Default for OPML {
fn default() -> Self {
OPML {
version: "2.0".to_string(),
head: Some(Head::default()),
body: Body::default(),
}
fn default() -> Self {
OPML {
version: "2.0".to_string(),
head: Some(Head::default()),
body: Body::default(),
}
}
}
/// The [Head](struct.Head.html) child element of [OPML](struct.OPML.html).
/// Contains the metadata of the OPML document.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize)]
/// The [`Head`] child element of [`OPML`]. Contains the metadata of the OPML
/// document.
#[derive(
XmlWrite,
XmlRead,
PartialEq,
Eq,
Debug,
Clone,
Default,
Serialize,
Deserialize,
)]
#[xml(tag = "head")]
pub struct Head {
/// The title of the document.
#[xml(flatten_text = "title")]
pub title: Option<String>,
/// The title of the document.
#[xml(flatten_text = "title")]
pub title: Option<String>,
/// A date-time (RFC822) indicating when the document was created.
#[xml(flatten_text = "dateCreated")]
pub date_created: Option<String>,
/// A date-time (RFC822) indicating when the document was created.
#[xml(flatten_text = "dateCreated")]
pub date_created: Option<String>,
/// A date-time (RFC822) indicating when the document was last modified.
#[xml(flatten_text = "dateModified")]
pub date_modified: Option<String>,
/// A date-time (RFC822) indicating when the document was last modified.
#[xml(flatten_text = "dateModified")]
pub date_modified: Option<String>,
/// The name of the document owner.
#[xml(flatten_text = "ownerName")]
pub owner_name: Option<String>,
/// The name of the document owner.
#[xml(flatten_text = "ownerName")]
pub owner_name: Option<String>,
/// The email address of the document owner.
#[xml(flatten_text = "ownerEmail")]
pub owner_email: Option<String>,
/// The email address of the document owner.
#[xml(flatten_text = "ownerEmail")]
pub owner_email: Option<String>,
/// A link to the website of the document owner.
#[xml(flatten_text = "ownerId")]
pub owner_id: Option<String>,
/// A link to the website of the document owner.
#[xml(flatten_text = "ownerId")]
pub owner_id: Option<String>,
/// A link to the documentation of the OPML format used for this document.
#[xml(flatten_text = "docs")]
pub docs: Option<String>,
/// A link to the documentation of the OPML format used for this document.
#[xml(flatten_text = "docs")]
pub docs: Option<String>,
/// A comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list.
#[xml(flatten_text = "expansionState")]
pub expansion_state: Option<String>,
/// A comma-separated list of line numbers that are expanded. The line numbers
/// in the list tell you which headlines to expand. The order is important.
/// For each element in the list, X, starting at the first summit, navigate
/// flatdown X times and expand. Repeat for each element in the list.
#[xml(flatten_text = "expansionState")]
pub expansion_state: Option<String>,
/// A number indicating which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied.
#[xml(flatten_text = "vertScrollState")]
pub vert_scroll_state: Option<i32>,
/// A number indicating which line of the outline is displayed on the top line
/// of the window. This number is calculated with the expansion state already
/// applied.
#[xml(flatten_text = "vertScrollState")]
pub vert_scroll_state: Option<i32>,
/// The pixel location of the top edge of the window.
#[xml(flatten_text = "windowTop")]
pub window_top: Option<i32>,
/// The pixel location of the top edge of the window.
#[xml(flatten_text = "windowTop")]
pub window_top: Option<i32>,
/// The pixel location of the left edge of the window.
#[xml(flatten_text = "windowLeft")]
pub window_left: Option<i32>,
/// The pixel location of the left edge of the window.
#[xml(flatten_text = "windowLeft")]
pub window_left: Option<i32>,
/// The pixel location of the bottom edge of the window.
#[xml(flatten_text = "windowBottom")]
pub window_bottom: Option<i32>,
/// The pixel location of the bottom edge of the window.
#[xml(flatten_text = "windowBottom")]
pub window_bottom: Option<i32>,
/// The pixel location of the right edge of the window.
#[xml(flatten_text = "windowRight")]
pub window_right: Option<i32>,
/// The pixel location of the right edge of the window.
#[xml(flatten_text = "windowRight")]
pub window_right: Option<i32>,
}
/// The [Body](struct.Body.html) child element of [OPML](struct.OPML.html). Contains all the [Outlines](struct.Outline.html).
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize)]
/// The [`Body`] child element of [`OPML`]. Contains all the [`Outline`]
/// elements.
#[derive(
XmlWrite,
XmlRead,
PartialEq,
Eq,
Debug,
Clone,
Default,
Serialize,
Deserialize,
)]
#[xml(tag = "body")]
pub struct Body {
/// All the top-level [Outline](struct.Outline.html) elements.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
/// All the top-level [`Outline`] elements.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
}
/// The [Outline](struct.Outline.html) element.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize)]
/// The [`Outline`] element.
#[derive(
XmlWrite,
XmlRead,
PartialEq,
Eq,
Debug,
Clone,
Default,
Serialize,
Deserialize,
)]
#[xml(tag = "outline")]
pub struct Outline {
/// Every outline element must have at least a text attribute, which is what is displayed when an outliner opens the OPML document.
/// Version 1.0 OPML documents may omit this attribute, so for compatibility and strictness this attribute is "technically optional" as it will be replaced by an empty String if it is omitted.
/// Text attributes may contain encoded HTML markup.
#[xml(default, attr = "text")]
pub text: String,
/// Every outline element must have at least a text attribute, which is what
/// is displayed when an outliner opens the OPML document.
///
/// Version 1.0 OPML documents may omit this attribute, so for compatibility
/// and strictness this attribute is "technically optional" as it will be
/// replaced by an empty String if it is omitted.
///
/// Text attributes may contain encoded HTML markup.
#[xml(default, attr = "text")]
pub text: String,
/// A string that indicates how the other attributes of the [Outline](struct.Outline.html) should be interpreted.
#[xml(attr = "type")]
pub r#type: Option<String>,
/// A string that indicates how the other attributes of the [`Outline`]
/// should be interpreted.
#[xml(attr = "type")]
pub r#type: Option<String>,
/// Indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented.
#[xml(attr = "isComment")]
pub is_comment: Option<bool>,
/// Indicating whether the outline is commented or not. By convention if an
/// outline is commented, all subordinate outlines are considered to also be
/// commented.
#[xml(attr = "isComment")]
pub is_comment: Option<bool>,
/// Indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts.
#[xml(attr = "isBreakpoint")]
pub is_breakpoint: Option<bool>,
/// Indicating whether a breakpoint is set on this outline. This attribute is
/// mainly necessary for outlines used to edit scripts.
#[xml(attr = "isBreakpoint")]
pub is_breakpoint: Option<bool>,
/// The date-time (RFC822) that this [Outline](struct.Outline.html) element was created.
#[xml(attr = "created")]
pub created: Option<String>,
/// The date-time (RFC822) that this [`Outline`] element was created.
#[xml(attr = "created")]
pub created: Option<String>,
/// A string of comma-separated slash-delimited category strings, in the format defined by the [RSS 2.0 category](http://cyber.law.harvard.edu/rss/rss.html#ltcategorygtSubelementOfLtitemgt) element. To represent a "tag," the category string should contain no slashes.
#[xml(attr = "category")]
pub category: Option<String>,
/// A string of comma-separated slash-delimited category strings, in the
/// format defined by the [RSS 2.0 category] element. To represent a "tag",
/// the category string should contain no slashes.
///
/// [RSS 2.0 category]: https://cyber.law.harvard.edu/rss/rss.html#ltcategorygtSubelementOfLtitemgt
#[xml(attr = "category")]
pub category: Option<String>,
/// Child [Outline](struct.Outline.html) elements of the current one.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
/// Child [`Outline`] elements of the current one.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
/// The HTTP address of the feed.
#[xml(attr = "xmlUrl")]
pub xml_url: Option<String>,
/// The HTTP address of the feed.
#[xml(attr = "xmlUrl")]
pub xml_url: Option<String>,
/// The top-level description element from the feed.
#[xml(attr = "description")]
pub description: Option<String>,
/// The top-level description element from the feed.
#[xml(attr = "description")]
pub description: Option<String>,
/// The top-level link element from the feed.
#[xml(attr = "htmlUrl")]
pub html_url: Option<String>,
/// The top-level link element from the feed.
#[xml(attr = "htmlUrl")]
pub html_url: Option<String>,
/// The top-level language element from the feed.
#[xml(attr = "language")]
pub language: Option<String>,
/// The top-level language element from the feed.
#[xml(attr = "language")]
pub language: Option<String>,
/// The top-level title element from the feed.
#[xml(attr = "title")]
pub title: Option<String>,
/// The top-level title element from the feed.
#[xml(attr = "title")]
pub title: Option<String>,
/// The version of the feed's format (such as RSS 0.91, 2.0, ...).
#[xml(attr = "version")]
pub version: Option<String>,
/// The version of the feed's format (such as RSS 0.91, 2.0, ...).
#[xml(attr = "version")]
pub version: Option<String>,
/// A link that can point to another OPML document or to something that can be displayed in a web browser.
#[xml(attr = "url")]
pub url: Option<String>,
/// A link that can point to another OPML document or to something that can
/// be displayed in a web browser.
#[xml(attr = "url")]
pub url: Option<String>,
}
impl Outline {
/// Helper function to add an [Outline](struct.Outline.html) element with `text` and `xml_url` attributes as a child element. Useful for creating grouped lists. This function [also exists on the OPML struct](struct.OPML.html#method.add_feed) for non-grouped lists.
///
/// # Example
///
/// ```rust
/// use opml::{Outline};
///
/// let mut group = Outline::default();
/// group.add_feed("Feed Name", "https://example.com/");
/// let added_feed = group.outlines.first().unwrap();
///
/// let expected_feed = &Outline {
/// text: "Feed Name".to_string(),
/// xml_url: Some("https://example.com/".to_string()),
/// ..Outline::default()
/// };
///
/// assert_eq!(added_feed, expected_feed);
/// ```
pub fn add_feed(&mut self, name: &str, url: &str) -> &mut Self {
self.outlines.push(Outline {
text: name.to_string(),
xml_url: Some(url.to_string()),
..Outline::default()
});
/// Helper function to add an [`Outline`] element with `text` and `xml_url`
/// attributes as a child element, useful for creating grouped lists. This
/// function also exists as [`OPML::add_feed`] for non-grouped lists.
///
/// # Example
///
/// ```rust
/// use opml::Outline;
///
/// let mut group = Outline::default();
/// group.add_feed("Feed Name", "https://example.com/");
/// let added_feed = group.outlines.first().unwrap();
///
/// let expected_feed = &Outline {
/// text: "Feed Name".to_string(),
/// xml_url: Some("https://example.com/".to_string()),
/// ..Outline::default()
/// };
///
/// assert_eq!(added_feed, expected_feed);
/// ```
pub fn add_feed(&mut self, name: &str, url: &str) -> &mut Self {
self.outlines.push(Outline {
text: name.to_string(),
xml_url: Some(url.to_string()),
..Outline::default()
});
self
}
self
}
}

View File

@ -17,7 +17,7 @@ fn test_opml_construction_1() -> Result<(), Box<dyn Error>> {
..Head::default()
});
let actual = opml.to_xml().unwrap();
let actual = opml.to_string().unwrap();
let expected = read("tests/samples/construction_1.opml")?;
assert_eq!(actual.trim(), expected.trim());
@ -26,6 +26,7 @@ fn test_opml_construction_1() -> Result<(), Box<dyn Error>> {
}
#[test]
#[allow(clippy::field_reassign_with_default)]
fn test_opml_construction_2() -> Result<(), Box<dyn Error>> {
let mut opml = OPML::default();
opml.head = Some(Head {
@ -51,7 +52,7 @@ fn test_opml_construction_2() -> Result<(), Box<dyn Error>> {
opml.body.outlines.push(rust_group);
opml.body.outlines.push(mozilla_group);
let actual = opml.to_xml().unwrap();
let actual = opml.to_string().unwrap();
let expected = read("tests/samples/construction_2.opml")?;
assert_eq!(actual.trim(), expected.trim());

View File

@ -0,0 +1,11 @@
use opml::OPML;
#[test]
#[allow(deprecated)]
fn test_deprecated_functions() {
let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
let document = OPML::new(xml).unwrap();
assert_eq!(document.version, "2.0");
assert!(document.to_xml().is_ok());
}

View File

@ -6,19 +6,19 @@ use opml::*;
#[should_panic]
fn test_invalid_xml() {
let sample = read("tests/samples/invalid_xml.opml").unwrap();
OPML::new(sample.as_str()).unwrap();
OPML::from_str(&sample).unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: invalid")]
fn test_invalid_opml_version() {
let sample = read("tests/samples/invalid_opml_version.opml").unwrap();
OPML::new(sample.as_str()).unwrap();
let res = OPML::from_str(&sample);
assert!(matches!(res, Err(Error::UnsupportedVersion(e)) if e == "invalid"));
}
#[test]
#[should_panic(expected = "OPML body has no outlines.")]
fn test_invalid_opml_no_outlines() {
let sample = read("tests/samples/invalid_opml_no_outlines.opml").unwrap();
OPML::new(sample.as_str()).unwrap();
let res = OPML::from_str(&sample);
assert!(matches!(res, Err(Error::BodyHasNoOutlines)));
}

View File

@ -0,0 +1,8 @@
<opml version="2.0">
<head>
<docs />
</head>
<body>
<outline text="Outline Text"/>
</body>
</opml>

View File

@ -1,5 +1,4 @@
use std::error::Error;
use std::fs;
use std::{error::Error, fs};
use opml::*;
@ -15,8 +14,8 @@ pub fn test_spec_samples() -> Result<(), Box<dyn Error>> {
];
for sample in samples {
let sample_content = fs::read_to_string(&sample)?;
OPML::new(sample_content.as_str())?;
let sample_content = fs::read_to_string(sample)?;
OPML::from_str(&sample_content)?;
}
Ok(())

View File

@ -5,7 +5,8 @@ use opml::*;
#[test]
fn test_minimum_valid_opml() {
assert_eq!(
OPML::new(&read("tests/samples/minimum_valid_opml.opml").unwrap()).unwrap(),
OPML::from_str(&read("tests/samples/minimum_valid_opml.opml").unwrap())
.unwrap(),
OPML {
version: "2.0".to_string(),
head: Some(Head::default()),
@ -19,11 +20,33 @@ fn test_minimum_valid_opml() {
);
}
#[test]
fn test_valid_empty_docs() {
assert_eq!(
OPML::from_str(&read("tests/samples/empty_docs.opml").unwrap()).unwrap(),
OPML {
version: "2.0".to_string(),
head: Some(Head {
docs: Some("".to_string()),
..Head::default()
}),
body: Body {
outlines: vec![Outline {
text: "Outline Text".to_string(),
..Outline::default()
}]
},
}
)
}
#[test]
fn test_valid_opml_with_everything() {
assert_eq!(
OPML::new(&read("tests/samples/valid_opml_with_everything.opml").unwrap())
.unwrap(),
OPML::from_str(
&read("tests/samples/valid_opml_with_everything.opml").unwrap()
)
.unwrap(),
OPML {
version: "2.0".to_string(),
head: Some(Head {
@ -81,7 +104,8 @@ fn test_valid_opml_with_everything() {
#[test]
fn test_valid_opml_1_0() {
assert_eq!(
OPML::new(&read("tests/samples/valid_opml_1_0.opml").unwrap()).unwrap(),
OPML::from_str(&read("tests/samples/valid_opml_1_0.opml").unwrap())
.unwrap(),
OPML {
version: "1.0".to_string(),
head: Some(Head::default()),
@ -95,3 +119,17 @@ fn test_valid_opml_1_0() {
}
);
}
#[test]
fn test_valid_from_reader() {
let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
assert!(OPML::from_reader(&mut xml.as_bytes()).is_ok());
}
#[test]
fn test_valid_to_writer() {
let document = OPML::default();
let mut writer = vec![];
assert!(document.to_writer(&mut writer).is_ok());
assert!(!writer.is_empty());
}

View File

@ -2,13 +2,13 @@
[package]
name = "opml_cli"
description = "An OPML parser for the command-line."
version = "0.3.0"
authors = ["Holllo <helllo@holllo.cc>"]
description = "OPML for the command-line."
repository = "https://git.bauke.xyz/Holllo/opml"
license = "MIT OR Apache-2.0"
repository = "https://github.com/Holllo/opml"
version = "1.1.6"
authors = ["Holllo <helllo@holllo.org>"]
edition = "2021"
readme = "../README.md"
edition = "2018"
keywords = ["xml", "opml"]
[[bin]]
@ -16,13 +16,21 @@ name = "opml"
path = "source/main.rs"
[dependencies]
clap = "2.33"
opml = { path = "../opml_api", version = "0.3" }
serde_json = "1.0"
serde_json = "1.0.111"
[dependencies.clap]
version = "4.4.18"
features = ["derive"]
[dependencies.opml]
path = "../opml_api"
version = "1.1.5"
[dependencies.serde]
version = "1.0"
version = "1.0.195"
features = ["derive"]
[dev-dependencies]
assert_cmd = "1.0"
assert_cmd = "2.0.13"
insta = "1.34.0"
test-case = "3.3.1"

202
opml_cli/LICENSE-Apache Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

21
opml_cli/LICENSE-MIT Normal file
View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2020-2024 Holllo <helllo@holllo.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,70 +1,43 @@
use std::fs::read_to_string;
use std::{fs::read_to_string, path::PathBuf};
use clap::{
crate_authors, crate_description, crate_version, App, Arg, ArgGroup,
};
use clap::Parser;
use opml::{Outline, OPML};
#[derive(Debug, Parser)]
#[clap(about, author, version)]
struct Args {
/// The OPML file to parse.
#[clap(short, long)]
file: PathBuf,
/// Output the OPML as JSON.
#[clap(long, group = "format", required = true)]
json: bool,
/// Output the OPML as pretty-printed JSON.
#[clap(long, group = "format", required = true)]
json_pretty: bool,
/// Only output the outline text and xmlUrl attributes when both are present
/// in the outline element.
#[clap(long, group = "format", required = true)]
rss: bool,
/// Print extra information while running.
#[clap(long)]
verbose: bool,
}
fn main() {
let cli = App::new("OPML CLI")
.about(crate_description!())
.author(crate_authors!())
.version(crate_version!())
.args(&[
// Format flags.
Arg::with_name("json")
.long("json")
.long_help("Output the OPML as JSON.")
.takes_value(false),
Arg::with_name("json pretty")
.long("json-pretty")
.long_help("Output the OPML as pretty-printed JSON.")
.takes_value(false),
Arg::with_name("rss")
.long("rss")
.long_help(
"Only output the outline text and xmlUrl attributes \
when both are present in the outline element.",
)
.takes_value(false),
// Boolean flags.
Arg::with_name("verbose")
.long("verbose")
.long_help("Print extra information while running.")
.takes_value(false),
// Options that are only allowed once.
Arg::with_name("file")
.long("file")
.long_help("The OPML file to parse.")
.required(true)
.short("f")
.takes_value(true),
])
.group(
ArgGroup::with_name("format")
.args(&["json", "json pretty", "rss"])
.required(true),
)
.get_matches();
// Extract format flags.
let json = cli.is_present("json");
let json_pretty = cli.is_present("json pretty");
let rss = cli.is_present("rss");
// Extract boolean flags.
let verbose = cli.is_present("verbose");
// Extract the various options.
let file = cli.value_of("file").unwrap();
let args = Args::parse();
// Read the file to string.
let xml = read_to_string(file).expect("Failed to read OPML file");
let xml = read_to_string(args.file).expect("Failed to read OPML file");
// Parse the OPML from the read file.
let opml = OPML::new(&xml).expect("Failed to parse OPML file");
let opml = OPML::from_str(&xml).expect("Failed to parse OPML file");
if rss {
if args.rss {
// Get all the outlines from the OPML document.
let outlines = extract_all_outlines(&opml.body.outlines);
@ -73,19 +46,19 @@ fn main() {
if let Some(xml_url) = outline.xml_url {
println!("{}", outline.text);
println!("{}", xml_url);
} else if verbose {
} else if args.verbose {
println!(
"Skipping \"{}\" because it did not have an xmlUrl attribute.",
outline.text
);
}
}
} else if json {
} else if args.json {
println!(
"{}",
serde_json::to_string(&opml).expect("Failed to convert OPML to JSON")
);
} else if json_pretty {
} else if args.json_pretty {
println!(
"{}",
serde_json::to_string_pretty(&opml)

25
opml_cli/tests/cli.rs Normal file
View File

@ -0,0 +1,25 @@
use {
assert_cmd::Command, insta::assert_display_snapshot, test_case::test_case,
};
const SAMPLE: &str = "tests/sample.opml";
#[test_case(&["--file", SAMPLE, "--json"], "json" ; "json")]
#[test_case(&["--file", SAMPLE, "--json-pretty"], "json_pretty" ; "json_pretty")]
#[test_case(&["--file", SAMPLE, "--rss"], "rss" ; "rss")]
fn test_valid(args: &[&str], name: &str) {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(args).assert().success().code(0);
let output = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
assert_display_snapshot!(name, output);
}
#[test_case(&["--rss"], "missing_file" ; "missing_file")]
#[test_case(&["--file", SAMPLE], "missing_format" ; "missing_format")]
#[test_case(&["--rss", "--json"], "multiple_formats" ; "multiple_formats")]
fn test_invalid(args: &[&'static str], name: &str) {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(args).assert().failure().code(2);
let output = String::from_utf8(assert.get_output().stderr.clone()).unwrap();
assert_display_snapshot!(name, output);
}

View File

@ -1,27 +0,0 @@
use std::fs::read_to_string;
use assert_cmd::Command;
const SAMPLE: &str = "tests/samples/youtube.opml";
#[test]
fn test_missing_file() {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(&["--rss"]).assert();
assert
.failure()
.code(1)
.stderr(read_to_string("tests/snapshots/missing-file.txt").unwrap());
}
#[test]
fn test_missing_format() {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(&["--file", SAMPLE]).assert();
assert
.failure()
.code(1)
.stderr(read_to_string("tests/snapshots/missing-format.txt").unwrap());
}

View File

@ -1,15 +0,0 @@
<opml version="1.1">
<body>
<outline text="YouTube Subscriptions"
title="YouTube Subscriptions">
<outline text="A YouTube Channel"
title="A YouTube Channel"
type="rss"
xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz1" />
<outline text="Another YouTube Channel"
title="Another YouTube Channel"
type="rss"
xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz2" />
</outline>
</body>
</opml>

View File

@ -0,0 +1,6 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
{"version":"2.0","head":{"title":"Rust Feeds","date_created":null,"date_modified":null,"owner_name":null,"owner_email":null,"owner_id":null,"docs":null,"expansion_state":null,"vert_scroll_state":null,"window_top":null,"window_left":null,"window_bottom":null,"window_right":null},"body":{"outlines":[{"text":"Rust Blog","type":null,"is_comment":null,"is_breakpoint":null,"created":null,"category":null,"outlines":[],"xml_url":"https://blog.rust-lang.org/feed.xml","description":null,"html_url":null,"language":null,"title":null,"version":null,"url":null},{"text":"Inside Rust","type":null,"is_comment":null,"is_breakpoint":null,"created":null,"category":null,"outlines":[],"xml_url":"https://blog.rust-lang.org/inside-rust/feed.xml","description":null,"html_url":null,"language":null,"title":null,"version":null,"url":null}]}}

View File

@ -0,0 +1,59 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
{
"version": "2.0",
"head": {
"title": "Rust Feeds",
"date_created": null,
"date_modified": null,
"owner_name": null,
"owner_email": null,
"owner_id": null,
"docs": null,
"expansion_state": null,
"vert_scroll_state": null,
"window_top": null,
"window_left": null,
"window_bottom": null,
"window_right": null
},
"body": {
"outlines": [
{
"text": "Rust Blog",
"type": null,
"is_comment": null,
"is_breakpoint": null,
"created": null,
"category": null,
"outlines": [],
"xml_url": "https://blog.rust-lang.org/feed.xml",
"description": null,
"html_url": null,
"language": null,
"title": null,
"version": null,
"url": null
},
{
"text": "Inside Rust",
"type": null,
"is_comment": null,
"is_breakpoint": null,
"created": null,
"category": null,
"outlines": [],
"xml_url": "https://blog.rust-lang.org/inside-rust/feed.xml",
"description": null,
"html_url": null,
"language": null,
"title": null,
"version": null,
"url": null
}
]
}
}

View File

@ -0,0 +1,13 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
error: the following required arguments were not provided:
--file <FILE>
--json
--json-pretty
Usage: opml --file <FILE> --json --json-pretty --rss
For more information, try '--help'.

View File

@ -0,0 +1,13 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
error: the following required arguments were not provided:
--json
--json-pretty
--rss
Usage: opml --file <FILE> --json --json-pretty --rss
For more information, try '--help'.

View File

@ -0,0 +1,10 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
error: the argument '--rss' cannot be used with '--json'
Usage: opml --file <FILE> --json --json-pretty --rss
For more information, try '--help'.

View File

@ -0,0 +1,9 @@
---
source: opml_cli/tests/cli.rs
expression: output
---
Rust Blog
https://blog.rust-lang.org/feed.xml
Inside Rust
https://blog.rust-lang.org/inside-rust/feed.xml

View File

@ -1,57 +0,0 @@
{
"version": "1.1",
"head": null,
"body": {
"outlines": [
{
"text": "YouTube Subscriptions",
"type": null,
"is_comment": null,
"is_breakpoint": null,
"created": null,
"category": null,
"outlines": [
{
"text": "A YouTube Channel",
"type": "rss",
"is_comment": null,
"is_breakpoint": null,
"created": null,
"category": null,
"outlines": [],
"xml_url": "https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz1",
"description": null,
"html_url": null,
"language": null,
"title": "A YouTube Channel",
"version": null,
"url": null
},
{
"text": "Another YouTube Channel",
"type": "rss",
"is_comment": null,
"is_breakpoint": null,
"created": null,
"category": null,
"outlines": [],
"xml_url": "https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz2",
"description": null,
"html_url": null,
"language": null,
"title": "Another YouTube Channel",
"version": null,
"url": null
}
],
"xml_url": null,
"description": null,
"html_url": null,
"language": null,
"title": "YouTube Subscriptions",
"version": null,
"url": null
}
]
}
}

View File

@ -1 +0,0 @@
{"version":"1.1","head":null,"body":{"outlines":[{"text":"YouTube Subscriptions","type":null,"is_comment":null,"is_breakpoint":null,"created":null,"category":null,"outlines":[{"text":"A YouTube Channel","type":"rss","is_comment":null,"is_breakpoint":null,"created":null,"category":null,"outlines":[],"xml_url":"https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz1","description":null,"html_url":null,"language":null,"title":"A YouTube Channel","version":null,"url":null},{"text":"Another YouTube Channel","type":"rss","is_comment":null,"is_breakpoint":null,"created":null,"category":null,"outlines":[],"xml_url":"https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz2","description":null,"html_url":null,"language":null,"title":"Another YouTube Channel","version":null,"url":null}],"xml_url":null,"description":null,"html_url":null,"language":null,"title":"YouTube Subscriptions","version":null,"url":null}]}}

View File

@ -1,7 +0,0 @@
error: The following required arguments were not provided:
--file <file>
USAGE:
opml --file <file> <--json|--json-pretty|--rss>
For more information try --help

View File

@ -1,7 +0,0 @@
error: The following required arguments were not provided:
<--json|--json-pretty|--rss>
USAGE:
opml [FLAGS] --file <file> <--json|--json-pretty|--rss>
For more information try --help

View File

@ -1,4 +0,0 @@
A YouTube Channel
https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz1
Another YouTube Channel
https://www.youtube.com/feeds/videos.xml?channel_id=abcdefghijklmnopqrstuvwxyz2

View File

@ -1,38 +0,0 @@
use std::fs::read_to_string;
use assert_cmd::Command;
const SAMPLE: &str = "tests/samples/youtube.opml";
#[test]
fn test_valid_rss() {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(&["--file", SAMPLE, "--rss"]).assert();
assert
.success()
.code(0)
.stdout(read_to_string("tests/snapshots/rss.txt").unwrap());
}
#[test]
fn test_valid_json() {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(&["--file", SAMPLE, "--json"]).assert();
assert
.success()
.code(0)
.stdout(read_to_string("tests/snapshots/json.json").unwrap());
}
#[test]
fn test_valid_json_pretty() {
let mut cmd = Command::cargo_bin("opml").unwrap();
let assert = cmd.args(&["--file", SAMPLE, "--json-pretty"]).assert();
assert
.success()
.code(0)
.stdout(read_to_string("tests/snapshots/json-pretty.json").unwrap());
}

2
rustfmt.toml Normal file
View File

@ -0,0 +1,2 @@
max_width = 80
tab_spaces = 2

3
rustup-toolchain.toml Normal file
View File

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["cargo", "clippy", "rustfmt", "rust-src"]

18
shell.nix Normal file
View File

@ -0,0 +1,18 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
rustup-toolchain = rust-bin.fromRustupToolchainFile ./rustup-toolchain.toml;
in
mkShell rec {
packages = [
cargo-audit
cargo-edit
cargo-insta
cargo-make
cargo-outdated
cargo-tarpaulin
rustup-toolchain
];
}