Skip to content

Commit 1a73214

Browse files
committed
Documentation up the wazoo
1 parent b1b011d commit 1a73214

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1+
//! Create markdown tables for [Locatarr](https://github.com/Locatarr/Locatarr)
2+
13
use itertools::Itertools;
24

35
use models::{Application, Applications};
46

57
pub mod models;
68

9+
/// Generate a fully valid markdown table from an [Applications] struct.
10+
///
11+
/// The resulting table is the minimum viable table and is not formatted in any way.
712
pub fn generate_md_table(apps: &Applications) -> String {
8-
"| **Service** | **Usage** | **Github** | **Reddit** |\n|-------------|-----------|------------|------------|\n".to_owned() +
13+
"| **Application** | **Description** | **Github** | **Reddit** |\n|-|-|-|-|\n".to_owned() +
914
&apps.applications
1015
.iter()
1116
.sorted()
1217
.map(generate_md_row)
1318
.join("\n")
1419
}
1520

21+
/// Create one markdown table row from a single [Application]
22+
///
23+
/// Copies the [Application::name] and [Application::description] fields in, and transforms [Application::github_slug] and
24+
/// [Application::subreddit] into proper markdown links.
1625
fn generate_md_row(app: &Application) -> String {
1726
let github_link = match &app.github_slug {
1827
Some(slug) => format!("[{}](https://github.com/{})", slug, slug),
1928
None => String::new(),
2029
};
2130

2231
let subreddit_link = match &app.subreddit {
23-
Some(sub) => format!("[{}](http://reddit.com/{})", sub, sub),
32+
Some(sub) => format!("[{}](https://reddit.com/{})", sub, sub),
2433
None => String::new(),
2534
};
2635

2736
// Output in table format of:
28-
// | Service | Usage | GitHub | Reddit |
37+
// | Application | Description | GitHub | Reddit |
2938
format!(
3039
"| {} | {} | {} | {} |",
3140
app.name, app.description, github_link, subreddit_link

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::PathBuf;
33

44
use locatarr_json_to_readme::{generate_md_table, models::Applications};
55

6+
/// Cli derives a clap parser to allow us to handle command line arguments
67
#[derive(Parser)]
78
#[command(version, about, long_about = None)]
89
struct Cli {
@@ -11,17 +12,24 @@ struct Cli {
1112
json_file_path: Option<PathBuf>,
1213
}
1314

15+
/// You Already Know What It Is!
16+
/// The entry point function.
1417
fn main() {
1518
let cli = Cli::parse();
1619

20+
// The following match checks for whether to create an input stream from a user provided
21+
// file path or from the standard input stream.
1722
let input_stream: Box<dyn std::io::Read + 'static> = match (
1823
cli.json_file_path.clone(),
1924
cli.json_file_path
2025
.unwrap_or("".into())
2126
.to_str()
2227
.unwrap_or(""),
2328
) {
29+
// Use stdin if we weren't provided a file path, or the file path was '-'
2430
(Some(_), "-") | (None, _) => Box::new(std::io::stdin()),
31+
32+
// Otherwise, use the provided file path
2533
(Some(file_path), _) => {
2634
if let Ok(file) = std::fs::File::open(file_path) {
2735
Box::new(file)

src/models.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
//! The models sub-crate holds all of the general purpose structs used throughout the library.
2+
13
use serde::{Deserialize, Serialize};
24

5+
/// Struct for the collection of a list of applications so that [serde] can deserialize a JSON
6+
/// file.
37
#[derive(Serialize, Deserialize, Debug, Clone)]
48
pub struct Applications {
59
pub applications: Vec<Application>,
610
}
711

12+
/// Holding struct for each application to place in a table
813
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
914
pub struct Application {
15+
/// The name of the application/service
1016
pub name: String,
17+
/// The description of the application/service
1118
pub description: String,
19+
/// Optional GitHub slug (`<owner>/<repo name>`) for the application/service
1220
pub github_slug: Option<String>,
21+
/// Optional subreddit slug (`r/<subreddit>`) for the application/service
1322
pub subreddit: Option<String>,
1423
}
1524

1625
impl Application {
26+
/// Create a new [Application] from various string references instead of owned strings
1727
#[allow(dead_code)] // Because I like this function here, but we aren't currently using it anywhere
1828
pub fn new_from_strs(
1929
name: &str,

0 commit comments

Comments
 (0)