mod gen;
mod syntax;

use gen::include;
use std::io::{self, Write};
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "cxxbridge", author)]
struct Opt {
    /// Input Rust source file containing #[cxx::bridge]
    #[structopt(parse(from_os_str), required_unless = "header")]
    input: Option<PathBuf>,

    /// Emit header with declarations only
    #[structopt(long)]
    header: bool,
}

fn write(content: impl AsRef<[u8]>) {
    let _ = io::stdout().lock().write_all(content.as_ref());
}

fn main() {
    let opt = Opt::from_args();

    match (opt.input, opt.header) {
        (Some(input), true) => write(gen::do_generate_header(&input)),
        (Some(input), false) => write(gen::do_generate_bridge(&input)),
        (None, true) => write(include::HEADER),
        (None, false) => unreachable!(), // enforced by required_unless
    }
}

mod gen;
mod syntax;

use gen::include;
use std::io::{self, Write};
use std::path::PathBuf;
use std::process;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "cxxbridge", author)]
struct Opt {
    /// Input Rust source file containing #[cxx::bridge]
    #[structopt(parse(from_os_str))]
    input: Option<PathBuf>,

    /// Emit header with declarations only
    #[structopt(long)]
    header: bool,
}

fn main() {
    let opt = Opt::from_args();

    if let Some(input) = opt.input {
        let gen = if opt.header {
            gen::do_generate_header
        } else {
            gen::do_generate_bridge
        };
        let bridge = gen(&input);
        let _ = io::stdout().lock().write_all(bridge.as_ref());
    } else if opt.header {
        let header = include::HEADER;
        let _ = io::stdout().lock().write_all(header.as_ref());
    } else {
        let _ = Opt::clap().after_help("").print_help();
        process::exit(1);
    }
}

--- 
+++ 
@@ -4,14 +4,13 @@
 use gen::include;
 use std::io::{self, Write};
 use std::path::PathBuf;
-use std::process;
 use structopt::StructOpt;
 
 #[derive(StructOpt, Debug)]
 #[structopt(name = "cxxbridge", author)]
 struct Opt {
     /// Input Rust source file containing #[cxx::bridge]
-    #[structopt(parse(from_os_str))]
+    #[structopt(parse(from_os_str), required_unless = "header")]
     input: Option<PathBuf>,
 
     /// Emit header with declarations only
@@ -19,22 +18,17 @@
     header: bool,
 }
 
+fn write(content: impl AsRef<[u8]>) {
+    let _ = io::stdout().lock().write_all(content.as_ref());
+}
+
 fn main() {
     let opt = Opt::from_args();
 
-    if let Some(input) = opt.input {
-        let gen = if opt.header {
-            gen::do_generate_header
-        } else {
-            gen::do_generate_bridge
-        };
-        let bridge = gen(&input);
-        let _ = io::stdout().lock().write_all(bridge.as_ref());
-    } else if opt.header {
-        let header = include::HEADER;
-        let _ = io::stdout().lock().write_all(header.as_ref());
-    } else {
-        let _ = Opt::clap().after_help("").print_help();
-        process::exit(1);
+    match (opt.input, opt.header) {
+        (Some(input), true) => write(gen::do_generate_header(&input)),
+        (Some(input), false) => write(gen::do_generate_bridge(&input)),
+        (None, true) => write(include::HEADER),
+        (None, false) => unreachable!(), // enforced by required_unless
     }
 }
Use clap's required_unless to enforce input file path
