extern crate npacked; extern crate docopt; use npacked::{Package, PackagedFile}; use docopt::Docopt; use std::path; /// Docopt usage string const USAGE: &'static str = r#" Usage: npk [options] [--] ... Options: -a, --append Append to an existing NPK. -c, --nocompress Don't compress files. -e, --encrypt OUTFILE Encrypt files. --userA Apply FILE_USER_A to files. --userB Apply FILE_USER_B to files. --userC Apply FILE_USER_C to files. --userD Apply FILE_USER_D to files. "#; fn main() { // Get arguments let args = Docopt::new(USAGE).and_then(|d| d.parse()).unwrap(); // Setup flags let mut flags = npacked::FILE_NONE; if !args.get_bool("-c") { flags = flags | npacked::FILE_COMPRESSED } if args.get_bool("-e") { unimplemented!() } if args.get_bool("--userA") { flags = flags | npacked::FILE_USER_A } if args.get_bool("--userB") { flags = flags | npacked::FILE_USER_B } if args.get_bool("--userC") { flags = flags | npacked::FILE_USER_C } if args.get_bool("--userD") { flags = flags | npacked::FILE_USER_D } // Create files let mut files = Vec::::new(); for file in args.get_vec("") { let path = path::Path::new(file); files.push(PackagedFile::new(path, path.file_name().unwrap().to_str(). unwrap().to_owned(), flags).unwrap()); } // Create/append to package if !args.get_bool("-a") { Package::create(args.get_str(""), &mut files).unwrap(); } else { Package::append(args.get_str(""), &mut files).unwrap(); } }