107
107
//! - v0.4.11 - support for overriding global `.bashdocrc` within a directory.
108
108
//! - v0.4.12 - descriptors can be split on ':' or whitespace
109
109
mod docs;
110
- use crate :: docs:: delims:: override_delims;
111
- use clap:: { load_yaml, App , ArgMatches } ;
112
- use notify:: { DebouncedEvent , RecommendedWatcher , RecursiveMode , Watcher } ;
113
- use std:: { sync:: mpsc:: channel, time:: Duration } ;
110
+ use crate :: docs:: runners:: * ;
111
+ use clap:: { load_yaml, App } ;
114
112
115
113
fn main ( ) {
116
114
let yaml = load_yaml ! ( "../cli.yml" ) ;
@@ -121,70 +119,3 @@ fn main() {
121
119
generate ( & matches) ;
122
120
}
123
121
}
124
-
125
- /// Given the arguments received via CLI from clap, setup and run with requested delimiters, file or directory, etc.
126
- pub fn generate < ' a > ( matches : & ' a ArgMatches < ' a > ) {
127
- let delims = match matches. subcommand ( ) {
128
- ( "override" , Some ( sub_m) ) => override_delims ( sub_m) ,
129
- _ => Delimiters :: get_delims ( ) ,
130
- } ;
131
- let all_em = start (
132
- matches. value_of ( "INPUT" ) . expect ( "directory glob not found" ) ,
133
- delims,
134
- )
135
- . unwrap ( ) ;
136
- if matches. is_present ( "json" ) {
137
- write_json ( & all_em, matches. value_of ( "json" ) . unwrap ( ) ) ;
138
- } else if matches. is_present ( "location" ) {
139
- to_html (
140
- & all_em,
141
- matches. value_of ( "location" ) ,
142
- matches. value_of ( "template" ) ,
143
- ) ;
144
- } else {
145
- for doc in & all_em {
146
- if matches. is_present ( "color" ) {
147
- printer ( doc, true ) ;
148
- } else {
149
- printer ( doc, false ) ;
150
- }
151
- }
152
- }
153
- }
154
-
155
- /// Given a request to watch files, Call `generate` on file write.
156
- pub fn watcher < ' a > ( matches : & ' a ArgMatches < ' a > ) {
157
- generate ( matches) ;
158
- let ( tx, rx) = channel ( ) ;
159
- let mut watcher: RecommendedWatcher = match Watcher :: new ( tx, Duration :: from_secs ( 2 ) ) {
160
- Ok ( d) => d,
161
- Err ( _) => {
162
- println ! ( "Provided path is invalid" ) ;
163
- exit ( 1 ) ;
164
- }
165
- } ;
166
- let path: String = if cfg ! ( windows) {
167
- String :: from ( matches. value_of ( "INPUT" ) . unwrap ( ) )
168
- } else {
169
- matches
170
- . value_of ( "INPUT" )
171
- . unwrap ( )
172
- . replace ( "~" , home_dir ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
173
- } ;
174
- watcher. watch ( & path, RecursiveMode :: Recursive ) . unwrap ( ) ;
175
- println ! ( "Watching for changes in {}..." , path) ;
176
- loop {
177
- match rx. recv ( ) {
178
- Ok ( event) => {
179
- generate ( & matches) ;
180
- if let DebouncedEvent :: Write ( e) = event {
181
- println ! (
182
- "Bashdoc updated to match changes to {}." ,
183
- e. as_path( ) . file_name( ) . unwrap( ) . to_str( ) . unwrap( )
184
- ) ;
185
- }
186
- }
187
- Err ( e) => println ! ( "watch error: {:?}" , e) ,
188
- }
189
- }
190
- }
0 commit comments