11use anyhow:: bail;
22use org_exporter:: ConfigOptions ;
3- use std:: fs:: { self , read_to_string , OpenOptions } ;
4- use std:: io:: { stdout , BufWriter , Read , Write } ;
3+ use std:: fs:: { self , OpenOptions , read_to_string } ;
4+ use std:: io:: { BufWriter , Read , Write , stdout } ;
55use std:: path:: { Path , PathBuf } ;
66use template:: Template ;
77use types:: { CliError , InpType , OutType } ;
88use utils:: { mkdir_recursively, relative_path_from} ;
99
1010use clap:: Parser ;
1111
12- mod template;
13- use crate :: cli:: Backend ;
1412mod cli;
13+ mod template;
1514mod types;
1615mod utils;
1716
@@ -45,12 +44,12 @@ fn run() -> anyhow::Result<()> {
4544 None => config_params. backend ,
4645 r => r,
4746 } ;
48- let output_path = if cli_params. output == "" {
47+ let output_path = if cli_params. output . is_empty ( ) {
4948 config_params. output
5049 } else {
5150 cli_params. output
5251 } ;
53- let input_path = if cli_params. input == "" {
52+ let input_path = if cli_params. input . is_empty ( ) {
5453 config_params. input
5554 } else {
5655 cli_params. input
@@ -62,10 +61,7 @@ fn run() -> anyhow::Result<()> {
6261 config_params. verbose
6362 } ;
6463
65- let backend = match backend {
66- Some ( b) => b,
67- None => Backend :: default ( ) ,
68- } ;
64+ let backend = backend. unwrap_or_default ( ) ;
6965
7066 let f = Path :: new ( & input_path) ;
7167 if !f. exists ( ) {
@@ -129,11 +125,11 @@ fn run() -> anyhow::Result<()> {
129125 // main loop to export files
130126 for file_path in & paths {
131127 if verbose {
132- writeln ! ( stdout, "input: {}" , file_path. display( ) ) . map_err ( |e| CliError :: from ( e ) ) ?;
128+ writeln ! ( stdout, "input: {}" , file_path. display( ) ) . map_err ( CliError :: from) ?;
133129 }
134130 if file_path. extension ( ) . is_some_and ( |x| x == "org" ) {
135131 let mut input_file = std:: fs:: File :: open ( file_path)
136- . map_err ( |e| CliError :: from ( e) . with_path ( & file_path) ) ?;
132+ . map_err ( |e| CliError :: from ( e) . with_path ( file_path) ) ?;
137133 let _num_bytes = input_file. read_to_string ( & mut file_contents) . map_err ( |e| {
138134 CliError :: from ( e)
139135 . with_path ( file_path)
@@ -165,7 +161,7 @@ fn run() -> anyhow::Result<()> {
165161 let mut build_str = String :: new ( ) ;
166162 for e in err_vec {
167163 build_str. push_str ( & e. to_string ( ) ) ;
168- build_str. push_str ( " \n " ) ;
164+ build_str. push ( '\n' ) ;
169165 }
170166 Err ( CliError :: new ( ) . with_cause ( & build_str) ) ?
171167 }
@@ -192,7 +188,7 @@ fn run() -> anyhow::Result<()> {
192188 // the destination we are writing to
193189 let mut full_output_path: PathBuf ;
194190 match dest {
195- OutType :: File ( ref output_file) => {
191+ OutType :: File ( output_file) => {
196192 full_output_path = output_file. to_path_buf ( ) ;
197193 }
198194 OutType :: Dir ( dest_path) => {
@@ -210,7 +206,7 @@ fn run() -> anyhow::Result<()> {
210206 }
211207 }
212208
213- mkdir_recursively ( & full_output_path. parent ( ) . unwrap ( ) ) ?;
209+ mkdir_recursively ( full_output_path. parent ( ) . unwrap ( ) ) ?;
214210 // truncate is needed to fully overwrite file contents
215211 OpenOptions :: new ( )
216212 . create ( true )
@@ -222,7 +218,7 @@ fn run() -> anyhow::Result<()> {
222218 . with_path ( & full_output_path)
223219 . with_cause ( "error in writing to destination file" )
224220 } ) ?
225- . write ( exported_content. as_bytes ( ) ) ?;
221+ . write_all ( exported_content. as_bytes ( ) ) ?;
226222
227223 if verbose {
228224 writeln ! (
@@ -257,12 +253,12 @@ fn run() -> anyhow::Result<()> {
257253 " -- symlinked: {}\n " ,
258254 & full_output_path. canonicalize( ) ?. display( )
259255 )
260- . map_err ( |e| CliError :: from ( e ) ) ?;
256+ . map_err ( CliError :: from) ?;
261257 }
262258 } else {
263259 fs:: copy ( file_path, & full_output_path) . map_err ( |e| {
264260 CliError :: from ( e)
265- . with_path ( & file_path)
261+ . with_path ( file_path)
266262 . with_cause ( "error in copying file to destination" )
267263 } ) ?;
268264 if verbose {
@@ -271,7 +267,7 @@ fn run() -> anyhow::Result<()> {
271267 " -- copied: {}\n " ,
272268 & full_output_path. canonicalize( ) ?. display( )
273269 )
274- . map_err ( |e| CliError :: from ( e ) ) ?;
270+ . map_err ( CliError :: from) ?;
275271 }
276272 }
277273 }
0 commit comments