File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ import sys
3
+
4
+ if len (sys .argv ) != 2 :
5
+ print ("""usage: rhai-autodocs-indexer.py <path-to-source-file>
6
+
7
+ This script searches for any `# rhai-autodocs:index:` comment and
8
+ automatically adds the index number following the order of the function
9
+ in the source file.
10
+
11
+ See the `FunctionOrder::ByIndex` option from the rhai-autodocs crate.
12
+ """ )
13
+ exit (1 )
14
+
15
+ file = sys .argv [1 ]
16
+
17
+ oldfile = open (file , 'r' )
18
+ newfile = open (f"{ file } .autodocs" , 'w' )
19
+
20
+ function_order = 1
21
+ for line in oldfile :
22
+ newline = ""
23
+ if "# rhai-autodocs:index:" in line :
24
+ newline = f" /// # rhai-autodocs:index:{ function_order } \n "
25
+ function_order += 1
26
+ else :
27
+ newline = line
28
+
29
+ newfile .write (newline )
Original file line number Diff line number Diff line change @@ -101,6 +101,15 @@ pub enum FunctionOrder {
101
101
/// #[rhai_fn(global)]
102
102
/// pub fn my_function2() {}
103
103
/// ```
104
+ ///
105
+ /// Adding, removing or re-ordering your functions from your api can be a chore
106
+ /// because you have to update all indexes by hand. Thankfully, you will found
107
+ /// a python script in the `scripts` folder of the `rhai-autodocs` repository
108
+ /// that will update the indexes by hand just for you.
109
+ ///
110
+ /// The script generates a .autodocs file from your original source file,
111
+ /// make sure to check that it did not mess with your source code using
112
+ /// a diff tool.
104
113
ByIndex ,
105
114
}
106
115
@@ -130,7 +139,7 @@ impl FunctionOrder {
130
139
{
131
140
let index = index
132
141
. parse :: < usize > ( )
133
- . map_err ( |err| AutodocsError :: PreProcessing ( format ! ( "failed to parsed order metadata: {}" , err . to_string ( ) ) ) ) ?;
142
+ . map_err ( |err| AutodocsError :: PreProcessing ( format ! ( "failed to parsed order metadata: {err}" ) ) ) ?;
134
143
135
144
if let Some ( slot) = ordered. get_mut ( index - 1 ) {
136
145
* slot = ( function. clone ( ) , polymorphisms. clone ( ) ) ;
You can’t perform that action at this time.
0 commit comments