Skip to content

Commit

Permalink
Merge pull request #7 from richiksc/feature/open-in-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin authored Jun 7, 2019
2 parents ff12bba + 463c0d5 commit aa34ef4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ base64 = "*"
colored = "1.6"
flate2 = "*"
sha1 = "0.6.0"
open = "1.2.2"
17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate structopt;
extern crate structopt_derive;
extern crate sha1;
extern crate tempfile;
extern crate open;

#[macro_use]
mod util;
Expand Down Expand Up @@ -62,6 +63,13 @@ pub struct Opt {
help = "Include these files in the results"
)]
attatched_paths: Vec<String>,

#[structopt(
short = "o",
long = "open",
help = "Open resulting HTML in default browser"
)]
open_in_browser: bool,
}

enum CsvEmbed {
Expand Down Expand Up @@ -122,8 +130,17 @@ fn main() {
attatched_files,
);

let output_path = output.clone();

let mut outfile = File::create(output).unwrap();
outfile.write_all(out.as_bytes()).unwrap();

if opt.open_in_browser {
match open::that(output_path) {
Ok(_) => (),
Err(_) => warning!("There was an error opening the browser."),
}
}
}

fn gen_html(
Expand Down
6 changes: 4 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ macro_rules! error {

macro_rules! warning {
($fmt:expr) => {
use colored::*;
println!(concat!("{}: ", $fmt), if cfg!(windows) { "warning".normal() } else { "warning".bold().yellow() });
{
use colored::*;
println!(concat!("{}: ", $fmt), if cfg!(windows) { "warning".normal() } else { "warning".bold().yellow() });
}
};
($fmt:expr, $($arg:tt)*) => {
use colored::*;
Expand Down

0 comments on commit aa34ef4

Please sign in to comment.