Skip to content

Commit

Permalink
fixed options
Browse files Browse the repository at this point in the history
  • Loading branch information
gmohre committed Mar 15, 2019
1 parent 796ca17 commit dc5a8d9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 94 deletions.
42 changes: 8 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-pants"
version = "0.0.4"
version = "0.0.5"
authors = ["Glenn Mohre <[email protected]>"]
edition = "2018"
readme = "README.md"
Expand All @@ -10,12 +10,11 @@ license = "Apache-2.0"
license_file = "LICENSE"

[dependencies]
argparse = "0.2.2"
atty = "0.2"
env_logger = "0.6.1"
chrono = { version = "0.4", optional = true }
futures = "0.1.0"
gumdrop = "0.5"
gumdrop_derive = "0.5"
hyper = "0.11.25"
hyper-tls = "0.1.3"
prettytable-rs = "0.6.7"
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
// limitations under the License.
#![allow(dead_code)]

extern crate argparse;
extern crate hyper;
extern crate hyper_tls;
extern crate url;
extern crate futures;
extern crate serde;

extern crate gumdrop;
#[allow(unused_imports)]
#[macro_use]
extern crate gumdrop_derive;

#[macro_use]
extern crate serde_derive;
extern crate serde_json;
Expand Down
79 changes: 27 additions & 52 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,42 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{
env,
process
process,
};
use cargo_pants::{package::Package, lockfile::Lockfile, client::OSSIndexClient, coordinate::Coordinate};
use gumdrop::Options;
use argparse::{Store, StoreTrue, ArgumentParser};

const CARGO_DEFAULT_LOCKFILE: &str = "Cargo.lock";
const NOPANTS: &str = "No Pants";

#[derive(Debug, Options)]
enum Opts {
#[options(help = "Audit Cargo.lock files for vulnerable crates using Sonatype OSSIndex")]
Pants(PantsOpts),
}

/// Options for the `cargo pants` subcommand
#[derive(Debug, Options)]
struct PantsOpts {
/// Lockfile Path
#[options(
short = "l",
long = "lockfile",
help = "The path to your Cargo.lock file"
)]
lockfile: Option<String>,

/// Pants Style
#[options(
short = "s",
long = "pants_style",
help = "pants style"
)]
pants_style: Option<String>,

}
impl Default for PantsOpts {
fn default() -> PantsOpts {
PantsOpts {
lockfile: None,
pants_style: None
}
}
}
fn main() {
let args: Vec<_> = env::args().collect();

let Opts::Pants(opts) = Opts::parse_args_default(&args[1..]).unwrap_or_else(|_| {
help(1);
});
let pants_style = opts.pants_style.as_ref().map(|s| s.as_ref()).unwrap_or("");

if pants_style.len() > 0 {
check_pants(pants_style.to_string());
let mut lockfile = CARGO_DEFAULT_LOCKFILE.to_string();
let mut pants_style = NOPANTS.to_string();
let mut help = false;
{
let mut ap = ArgumentParser::new();
ap.set_description("Audit Cargo.lock files for vulnerable crates using Sonatype OSSIndex");
ap.refer(&mut lockfile)
.add_option(&["-l", "--lockfile"], Store,
"Name for the greeting");
ap.refer(&mut pants_style)
.add_option(&["-p", "--pants_style"], Store,
"Pants Style");
ap.refer(&mut help)
.add_option(&["--help"], StoreTrue,
"Help");
ap.parse_args_or_exit();
}

let lockfile_path = opts.lockfile.as_ref().map(|s| s.as_ref()).unwrap_or(CARGO_DEFAULT_LOCKFILE);
audit(lockfile_path.to_string());
if pants_style != NOPANTS {
check_pants(pants_style);
}
if help {
helper(0);
}
audit(lockfile);
}

fn audit(lockfile_path: String) -> ! {

let lockfile : Lockfile = Lockfile::load(lockfile_path).unwrap_or_else(|e| {
println!("{}", e);
process::exit(3);
Expand Down Expand Up @@ -133,9 +109,8 @@ fn check_pants(n: String) -> ! {
}

/// Print help message
fn help(code: i32) -> ! {
fn helper(code: i32) -> ! {
println!("Usage: cargo pants [OPTIONS]");
println!();
println!("{}", Opts::command_usage("lockfile").unwrap());
process::exit(code);
}

0 comments on commit dc5a8d9

Please sign in to comment.