Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #354 from fastly/fdenis/app_from_crate
Browse files Browse the repository at this point in the history
Use app_from_crate!() instead of hardcoding clap base parameters
  • Loading branch information
acfoltzer authored Nov 1, 2019
2 parents 24df40c + 28d7cd9 commit 4b949a7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
7 changes: 3 additions & 4 deletions lucet-builtins/wasmonkey/src/bin/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{PatcherConfig, WError};
use clap::{App, Arg};
use clap::Arg;
use std::path::PathBuf;

#[derive(Default, Clone, Debug)]
Expand All @@ -11,9 +11,8 @@ pub struct Config {

impl Config {
pub fn parse_cmdline() -> Result<Self, WError> {
let matches = App::new("wasmonkey")
.version("1.0")
.about("Transforms WASM exports to imports")
let _ = include_str!("../../../Cargo.toml");
let matches = app_from_crate!()
.arg(
Arg::with_name("input_file")
.short("i")
Expand Down
3 changes: 3 additions & 0 deletions lucet-builtins/wasmonkey/src/bin/wasmonkey.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod config;

#[macro_use]
extern crate clap;

use crate::config::*;
use wasmonkey::*;

Expand Down
10 changes: 6 additions & 4 deletions lucet-idl/lucet-idl-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use clap::{App, Arg};
#[macro_use]
extern crate clap;

use clap::Arg;
use env_logger;
use log::{debug, info};
use lucet_idl::{parse_package, Module, Package};
Expand Down Expand Up @@ -89,9 +92,8 @@ struct ExeConfig {

impl ExeConfig {
pub fn parse() -> Self {
let matches = App::new("lucet-idl-test")
.version("0.1.0")
.about("lucet-idl testing tool")
let _ = include_str!("../Cargo.toml");
let matches = app_from_crate!()
.arg(
Arg::with_name("input")
.required(false)
Expand Down
10 changes: 6 additions & 4 deletions lucet-idl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use clap::{App, Arg};
#[macro_use]
extern crate clap;

use clap::Arg;
use lucet_idl::{run, Config, IDLError};
use std::fs::File;
use std::io;
Expand All @@ -15,9 +18,8 @@ pub struct ExeConfig {

impl ExeConfig {
pub fn parse() -> Result<Self, IDLError> {
let matches = App::new("lucet-idl")
.version(env!("CARGO_PKG_VERSION"))
.about("lucet_idl code generator")
let _ = include_str!("../Cargo.toml");
let matches = app_from_crate!()
.arg(
Arg::with_name("input")
.required(true)
Expand Down
8 changes: 6 additions & 2 deletions lucet-spectest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use clap::{App, Arg};
#[macro_use]
extern crate clap;

use clap::Arg;
use failure::{format_err, Error};
use lucet_spectest;
use std::path::PathBuf;

fn main() -> Result<(), Error> {
let matches = App::new("lucet-spectest")
let _ = include_str!("../Cargo.toml");
let matches = app_from_crate!()
.arg(
Arg::with_name("input")
.multiple(false)
Expand Down
3 changes: 3 additions & 0 deletions lucetc/lucetc/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod options;

#[macro_use]
extern crate clap;

use crate::options::{CodegenOutput, ErrorStyle, Options};
use failure::{format_err, Error, ResultExt};
use log::info;
Expand Down
5 changes: 3 additions & 2 deletions lucetc/lucetc/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgMatches, Values};
use clap::{Arg, ArgMatches, Values};
use failure::Error;
use lucetc::{CpuFeatures, HeapSettings, OptLevel, SpecificFeature, TargetCpu};
use std::path::PathBuf;
Expand Down Expand Up @@ -228,7 +228,8 @@ impl Options {
})
}
pub fn get() -> Result<Self, Error> {
let m = App::new("lucetc")
let _ = include_str!("../Cargo.toml");
let m = app_from_crate!()
.arg(
Arg::with_name("precious")
.long("--precious")
Expand Down

0 comments on commit 4b949a7

Please sign in to comment.