1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! # rustdoc-llms
//!
//! Rust documentation helper that helps a Rust crate developer generate a file
//! `llms.txt` that helps provide context to large language models (LLMs).
//!
//! Thanks to excellent work by the Rust team, rustdoc team, and rustdoc-md team.
//!
//! ## How to use this
//!
//! Install:
//!
//! ```sh
//! cargo install rustdoc-llms
//! ```
//!
//! Use the tool when you're working on a crate and you want to document it:
//!
//! ```sh
//! rustdoc-llms
//! ```
//!
//! The tool creates two files:
//!
//! * `target/doc/foo_bar.json` (this uses your own crate naming convention)
//!
//! * `target/doc/llms.txt` (this is a markdown file created by rustdoc-md)
//!
//! If you like, you can copy these files to the top level of your repository, which
//! can make the files easier to find for search engines and AI systems:
//!
//! ```sh
//! cp target/doc/foo_bar.json llms.json
//! cp target/doc/llms.txt llms.txt
//! ```
//!
//! ## Scope
//!
//! This Rust crate is deliberately small and simple. The purpose is to make it
//! slightly-easier to generate `llms` based on what's currently easy and available
//! for Rust crate developers.
//!
//! Currently this tool calls existing command line interfaces, using `cargo` and
//! `rustdoc-md` with specialized compiler flags. If this tool is useful in
//! practice, then I intend to iterate to add command line arguments, options,
//! tests, and the like.
//!
//! ## Contributing
//!
//! Pull requests are welcome. Issues are welcome.
//!
//! If you want to help in other ways, or provide constructive criticism, or ask
//! questions directly, then please feel free to contact me. I'm Joel Parker
//! Henderson and my email is <joel@joelparkerhenderson.com>.
//!
//! ## What this does
//!
//! This implements the help description [here](https://crates.io/crates/rustdoc-md).
//!
//! Step 1: Generate JSON documentation:
//!
//! ```sh
//! RUSTC_BOOTSTRAP=1 RUSTDOCFLAGS="-Z unstable-options --output-format json" cargo doc --no-deps
//! ```
//!
//! Step 2: Convert from JSON into Markdown:
//!
//! ```sh
//! rustdoc-md --path target/doc/foo_bar.json --output target/doc/foo_bar.md
//! ```
//!
//! Step 3: Copy from Markdown file into LLMs file:
//!
//! ```sh
//! cp target/doc/foo_bar.json llms.json
//! cp target/doc/foo_bar.md llms.txt
//! ```
use Command;
use ;
/// Run this command to generate the documentation LLMS file.
///
/// Example:
///
/// ```sh
/// rustdoc-llms
/// ```
///
/// You may wish to copy the output files to the root of your crate:
///
/// ```sh
/// cp target/doc/foo_bar.json llms.json
/// cp target/doc/llms.txt llms.txt
/// ```
///
/// Get the path to the file `Cargo.toml`.
/// Get the target JSON file base name; this file is what cargo doc generates.
/// The name is the crate's lib target's name with all - chars turned into _.
///
/// Example:
///
/// ```rust
/// use rustdoc_llms::*;
/// let path = rustdoc_md::documentation_json_path();
/// ```
///
/// This is the name of the goal LLMS file that will be generated by rustdoc-md.
/// The industry standard file name is `llms.txt` though you can use anything.
///
/// Example:
///
/// ```rust
/// use rustdoc_llms::*;
/// let path = rustdoc_md::documentation_llms_path();
/// ```
///
/// Run cargo doc with args to output one JSON file with all the combined documentation.
///
/// Example:
///
/// ```rust
/// use rustdoc_llms::*;
/// let path = rustdoc_md::generate_documentation_json_file();
/// ```
///
/// Run rustdoc-md with an input file path and output file path.
///
/// Example:
///
/// ```rust
/// use rustdoc_llms::*;
/// let input_json_path = rustdoc_md::documentation_json_path();
/// let output_llms_path = rustdoc_md::documentation_llms_path();
/// let path = rustdoc_md::generate_documentation_llms_file(input_json_path, output_llms_path);
/// ```
///