main.rs
1 // 2 // This file is part of filemark. 3 // 4 // filemark is free software: you can redistribute it and/or modify it under the 5 // terms of the GNU General Public License as published by the Free Software 6 // Foundation, either version 3 of the License, or (at your option) any later 7 // version. 8 // 9 // filemark is distributed in the hope that it will be useful, but WITHOUT ANY 10 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 // A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License along with 14 // filemark. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 use filemark::{Renderer, RendererOptions}; 18 use std::io::Write; 19 use std::env; 20 21 const USAGE: &'static str = r#" 22 23 Usage: filemark <REVIEWFILE> <ROOTPATH> [FLAG...] 24 25 REVIEWFILE: source gmi file 26 ROOTPATH: root folder for files 27 FLAG: 28 --numberlines enables line numbering 29 --linedesc fallback description uses line ref instead of URL 30 --draft renders errors in the output 31 --markdown render as markdown 32 --html render as html 33 "#; 34 35 enum Format { 36 Gemtext, 37 Html, 38 Markdown, 39 } 40 41 fn main() { 42 let mut args = env::args(); 43 let _arg0 = args.next().expect(USAGE); 44 let reviewfile = args.next().expect(USAGE); 45 let rootpath = args.next().expect(USAGE); 46 47 let mut opts = RendererOptions::new(); 48 let mut format = Format::Gemtext; 49 50 for flag in args { 51 if flag == "--numberlines" { 52 opts = opts.number_lines(true); 53 } else if flag == "--draft" { 54 opts = opts.draft(true); 55 } else if flag == "--linedesc" { 56 opts = opts.linedesc(true); 57 } else if flag == "--markdown" { 58 format = Format::Markdown; 59 } else if flag == "--html" { 60 format = Format::Html; 61 } else { 62 eprintln!("{USAGE}"); 63 panic!("Unknown flag: {}", flag); 64 } 65 } 66 let r = Renderer::new(opts); 67 68 let output = match format { 69 Format::Markdown => { 70 r.render_markdown(reviewfile, rootpath) 71 .expect("Failed to render") 72 } 73 Format::Gemtext => { 74 r.render_gemtext(reviewfile, rootpath) 75 .expect("Failed to render") 76 } 77 Format::Html => { 78 r.render_html(reviewfile, rootpath) 79 .expect("Failed to render") 80 } 81 }; 82 std::io::stdout().write(&output).unwrap(); 83 }