From 25529d4f81a1430bde97320b847f3f69625173c9 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:20:31 +0100
Subject: [PATCH 1/8] Added ::= tests/assets/gpl-3.0-inner.rs
---
tests/assets/gpl-3.0-inner.rs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 tests/assets/gpl-3.0-inner.rs
diff --git a/tests/assets/gpl-3.0-inner.rs b/tests/assets/gpl-3.0-inner.rs
new file mode 100644
index 00000000..99ad6503
--- /dev/null
+++ b/tests/assets/gpl-3.0-inner.rs
@@ -0,0 +1,14 @@
+/// Copyright (C) 2023 Kevin Matthes
+///
+/// This program is free software: you can redistribute it and/or modify
+/// it under the terms of the GNU General Public License as published by
+/// the Free Software Foundation, either version 3 of the License, or
+/// (at your option) any later version.
+///
+/// This program is distributed in the hope that it will be useful,
+/// but WITHOUT ANY WARRANTY; without even the implied warranty of
+/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+/// GNU General Public License for more details.
+///
+/// You should have received a copy of the GNU General Public License
+/// along with this program. If not, see .
From 74f5d74ad21497eb609a4b64291245d2a83242a9 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:21:11 +0100
Subject: [PATCH 2/8] Added ::= tests/assets/gpl-3.0-outer.rs
---
tests/assets/gpl-3.0-outer.rs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 tests/assets/gpl-3.0-outer.rs
diff --git a/tests/assets/gpl-3.0-outer.rs b/tests/assets/gpl-3.0-outer.rs
new file mode 100644
index 00000000..455a722b
--- /dev/null
+++ b/tests/assets/gpl-3.0-outer.rs
@@ -0,0 +1,14 @@
+//! Copyright (C) 2023 Kevin Matthes
+//!
+//! This program is free software: you can redistribute it and/or modify
+//! it under the terms of the GNU General Public License as published by
+//! the Free Software Foundation, either version 3 of the License, or
+//! (at your option) any later version.
+//!
+//! This program is distributed in the hope that it will be useful,
+//! but WITHOUT ANY WARRANTY; without even the implied warranty of
+//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//! GNU General Public License for more details.
+//!
+//! You should have received a copy of the GNU General Public License
+//! along with this program. If not, see .
From f2382c8967ea4bc73b2603e2ceb5bdaa73c82267 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:22:30 +0100
Subject: [PATCH 3/8] Added ::= src/utilities.rs
---
src/utilities.rs | 101 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 src/utilities.rs
diff --git a/src/utilities.rs b/src/utilities.rs
new file mode 100644
index 00000000..c1f66d49
--- /dev/null
+++ b/src/utilities.rs
@@ -0,0 +1,101 @@
+/*********************** GNU General Public License 3.0 ***********************\
+| |
+| Copyright (C) 2023 Kevin Matthes |
+| |
+| This program is free software: you can redistribute it and/or modify |
+| it under the terms of the GNU General Public License as published by |
+| the Free Software Foundation, either version 3 of the License, or |
+| (at your option) any later version. |
+| |
+| This program is distributed in the hope that it will be useful, |
+| but WITHOUT ANY WARRANTY; without even the implied warranty of |
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+| GNU General Public License for more details. |
+| |
+| You should have received a copy of the GNU General Public License |
+| along with this program. If not, see . |
+| |
+\******************************************************************************/
+
+use crate::PatternIOProcessor;
+use std::path::PathBuf;
+use sysexits::Result;
+
+/// Extract Markdown code from Rust documentation comments.
+#[derive(clap::Parser, Clone)]
+pub struct Rs2md {
+ /// Whether to extract Rust documentation comments starting with `///`.
+ #[arg(long = "inner")]
+ extract_inner: bool,
+
+ /// Whether to extract Rust documentation comments starting with `//!`.
+ #[arg(long = "outer")]
+ extract_outer: bool,
+
+ /// The Rust files to read from, defaulting to [`std::io::Stdin`], if
+ /// omitted.
+ #[arg(long = "input", short)]
+ input_file: Vec,
+
+ /// The Markdown file to write to, defaulting to [`std::io::Stdout`], if
+ /// omitted.
+ #[arg(long = "output", short)]
+ output_file: Option,
+}
+
+impl Rs2md {
+ /// Extract Markdown code from Rust documentation comments.
+ ///
+ /// # Errors
+ ///
+ /// See
+ ///
+ /// - [`PatternIOProcessor::io`]
+ pub fn main(&self) -> Result<()> {
+ (|s: String| {
+ s.lines()
+ .map(str::trim_start)
+ .filter(|l| {
+ (self.extract_inner && l.starts_with("///"))
+ || (self.extract_outer && l.starts_with("//!"))
+ })
+ .map(|l| {
+ if l.len() > 3 {
+ l.split_at(4).1.trim_end().to_string() + "\n"
+ } else {
+ "\n".to_string()
+ }
+ })
+ .collect::()
+ })
+ .io(&self.input_file, &self.output_file)
+ }
+
+ /// Create a new instance.
+ pub fn new(
+ input_file: Vec,
+ output_file: Option,
+ extract_inner: bool,
+ extract_outer: bool,
+ ) -> Self
+ where
+ PathBuf: From,
+ {
+ Self {
+ extract_inner,
+ extract_outer,
+ input_file: {
+ let mut i = Vec::new();
+
+ for file in input_file {
+ i.push(file.into());
+ }
+
+ i
+ },
+ output_file: output_file.map(Into::into),
+ }
+ }
+}
+
+/******************************************************************************/
From 1b37351f72ca170f741a9ae4cdc6a1b11de23015 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:24:11 +0100
Subject: [PATCH 4/8] Added ::= Rs2md
---
src/lib.rs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lib.rs b/src/lib.rs
index dc0e62c4..36c39db8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -450,6 +450,7 @@ mod macros;
mod pattern;
mod running;
mod traits;
+mod utilities;
mod version;
pub use crate::{
@@ -474,6 +475,7 @@ pub use crate::{
AppendAsLine, ColourMessage, ConvertBuffer, FromMd, FromRon, FromRst,
FromXml, Prefer, ReadFile, ToMd, ToRon, ToRst, ToStderr, ToXml,
},
+ utilities::Rs2md,
version::{Range as VersionRange, Version},
};
From 2ca90eaba0541903c013c090a3c88740839bf098 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:25:02 +0100
Subject: [PATCH 5/8] Changed ::= rs2md: outsource logic to dedicated struct
---
src/application.rs | 47 ++--------------------------------------------
1 file changed, 2 insertions(+), 45 deletions(-)
diff --git a/src/application.rs b/src/application.rs
index 1ca8af92..3c8f5f71 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -85,25 +85,7 @@ pub enum Action {
Ronlog(crate::Ronlog),
/// Extract Markdown code from Rust documentation comments.
- Rs2md {
- /// Whether to extract Rust documentation comments starting with `///`.
- #[arg(long = "inner")]
- extract_inner: bool,
-
- /// Whether to extract Rust documentation comments starting with `//!`.
- #[arg(long = "outer")]
- extract_outer: bool,
-
- /// The Rust files to read from, defaulting to [`std::io::Stdin`], if
- /// omitted.
- #[arg(long = "input", short)]
- input_file: Vec,
-
- /// The Markdown file to write to, defaulting to [`std::io::Stdout`], if
- /// omitted.
- #[arg(long = "output", short)]
- output_file: Option,
- },
+ Rs2md(crate::Rs2md),
/// Remove CRLFs from the given file.
Uncrlf {
@@ -122,23 +104,6 @@ pub enum Action {
}
impl Action {
- fn rs2md(s: &str, extract_inner: bool, extract_outer: bool) -> String {
- s.lines()
- .map(str::trim_start)
- .filter(|l| {
- (extract_inner && l.starts_with("///"))
- || (extract_outer && l.starts_with("//!"))
- })
- .map(|l| {
- if l.len() > 3 {
- l.split_at(4).1.trim_end().to_string() + "\n"
- } else {
- "\n".to_string()
- }
- })
- .collect::()
- }
-
/// Execute the selected action.
///
/// # Errors
@@ -196,15 +161,7 @@ impl Action {
+ "\", }, ], \"settings\" : [], }\n",
)),
Self::Ronlog(r) => r.main(),
- Self::Rs2md {
- extract_inner,
- extract_outer,
- input_file,
- output_file,
- } => (|s: String| -> String {
- Self::rs2md(&s, *extract_inner, *extract_outer)
- })
- .io(input_file, output_file),
+ Self::Rs2md(r) => r.main(),
Self::Uncrlf {
file_to_edit,
input_file,
From a1d32f94120efdfb9b70c0adbf73400f500eebac Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:28:08 +0100
Subject: [PATCH 6/8] Added ::= src/utilities.rs
---
tests/utilities.rs | 156 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
create mode 100644 tests/utilities.rs
diff --git a/tests/utilities.rs b/tests/utilities.rs
new file mode 100644
index 00000000..d11e6e7c
--- /dev/null
+++ b/tests/utilities.rs
@@ -0,0 +1,156 @@
+/*********************** GNU General Public License 3.0 ***********************\
+| |
+| Copyright (C) 2023 Kevin Matthes |
+| |
+| This program is free software: you can redistribute it and/or modify |
+| it under the terms of the GNU General Public License as published by |
+| the Free Software Foundation, either version 3 of the License, or |
+| (at your option) any later version. |
+| |
+| This program is distributed in the hope that it will be useful, |
+| but WITHOUT ANY WARRANTY; without even the implied warranty of |
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+| GNU General Public License for more details. |
+| |
+| You should have received a copy of the GNU General Public License |
+| along with this program. If not, see . |
+| |
+\******************************************************************************/
+
+use aeruginous::{ReadFile, Rs2md};
+use std::fs::remove_file;
+
+macro_rules! make_test {
+ ( @rs2md @none $( $n:ident -> $i:expr , $o:expr ),+ ) => {
+ $(
+ #[test]
+ fn $n() {
+ assert!(Rs2md::new(
+ vec![
+ "tests/assets/gpl-3.0-inner.rs",
+ "tests/assets/gpl-3.0-outer.rs"
+ ],
+ Some(concat!(stringify!($n), ".md")),
+ $i,
+ $o
+ ).main().is_ok());
+
+ assert!(
+ concat!(stringify!($n), ".md")
+ .read()
+ .unwrap()
+ .is_empty()
+ );
+
+ remove_file(concat!(stringify!($n), ".md")).unwrap();
+ }
+ )+
+ };
+
+ ( @rs2md @once $( $n:ident -> $i:expr , $o:expr ),+ ) => {
+ $(
+ #[test]
+ fn $n() {
+ assert!(Rs2md::new(
+ vec![
+ "tests/assets/gpl-3.0-inner.rs",
+ "tests/assets/gpl-3.0-outer.rs"
+ ],
+ Some(concat!(stringify!($n), ".md")),
+ $i,
+ $o
+ ).main().is_ok());
+
+ assert_eq!(
+ concat!(stringify!($n), ".md").read().unwrap(),
+ "\
+Copyright (C) 2023 Kevin Matthes
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+"
+ );
+
+ remove_file(concat!(stringify!($n), ".md")).unwrap();
+ }
+ )+
+ };
+
+ ( @rs2md @twice $( $n:ident -> $i:expr , $o:expr ),+ ) => {
+ $(
+ #[test]
+ fn $n() {
+ assert!(Rs2md::new(
+ vec![
+ "tests/assets/gpl-3.0-inner.rs",
+ "tests/assets/gpl-3.0-outer.rs"
+ ],
+ Some(concat!(stringify!($n), ".md")),
+ $i,
+ $o
+ ).main().is_ok());
+
+ assert_eq!(
+ concat!(stringify!($n), ".md").read().unwrap(),
+ "\
+Copyright (C) 2023 Kevin Matthes
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+Copyright (C) 2023 Kevin Matthes
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+"
+ );
+
+ remove_file(concat!(stringify!($n), ".md")).unwrap();
+ }
+ )+
+ };
+}
+
+make_test!(@rs2md @none
+ rs2md_neither_inner_nor_outer -> false, false
+);
+
+make_test!(@rs2md @once
+ rs2md_only_inner -> true, false,
+ rs2md_only_outer -> false, true
+);
+
+make_test!(@rs2md @twice
+ rs2md_both_inner_and_outer -> true, true
+);
+
+/******************************************************************************/
From 1fe3fe11af3ea9a300d1cffc765ca59283a521b4 Mon Sep 17 00:00:00 2001
From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sun, 31 Dec 2023 21:29:46 +0000
Subject: [PATCH 7/8] Create summary of recent changes
---
...212945_GitHub_Actions_rs2md-utility-struct.ron | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
diff --git a/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron b/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
new file mode 100644
index 00000000..46da550c
--- /dev/null
+++ b/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
@@ -0,0 +1,15 @@
+(
+ references: {},
+ changes: {
+ "Added": [
+ "Rs2md",
+ "src/utilities.rs",
+ "src/utilities.rs",
+ "tests/assets/gpl-3.0-inner.rs",
+ "tests/assets/gpl-3.0-outer.rs",
+ ],
+ "Changed": [
+ "rs2md: outsource logic to dedicated struct",
+ ],
+ },
+)
From 4e042f403119a5a1a1db2dc88b6b1647c3986113 Mon Sep 17 00:00:00 2001
From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com>
Date: Sun, 31 Dec 2023 22:31:00 +0100
Subject: [PATCH 8/8] Skip ::= fix typo
---
.../20231231_212945_GitHub_Actions_rs2md-utility-struct.ron | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron b/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
index 46da550c..5da11969 100644
--- a/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
+++ b/changelog.d/20231231_212945_GitHub_Actions_rs2md-utility-struct.ron
@@ -4,7 +4,7 @@
"Added": [
"Rs2md",
"src/utilities.rs",
- "src/utilities.rs",
+ "tests/utilities.rs",
"tests/assets/gpl-3.0-inner.rs",
"tests/assets/gpl-3.0-outer.rs",
],