Skip to content

Commit

Permalink
chore: Upgrade structopt
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 18, 2019
1 parent 948eb0e commit 5e6e4b9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 102 deletions.
47 changes: 5 additions & 42 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ iterate_unstable = []
typos = { version = "0.1", path = "typos" }
typos-dict = { version = "0.1", path = "typos-dict" }
failure = "0.1"
structopt = "0.2"
structopt = "0.3"
clap = "2"
clap-verbosity-flag = "0.2.0"
clap-verbosity-flag = "0.3"
ignore = "0.4"
serde = { version = "1.0", features = ["derive"] }
toml = "0.4"
Expand Down
102 changes: 44 additions & 58 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ struct Args {
/// Custom config file
custom_config: Option<std::path::PathBuf>,

#[structopt(long = "isolated")]
#[structopt(long)]
/// Ignore implicit configuration files.
isolated: bool,

#[structopt(flatten)]
overrides: FileArgs,

#[structopt(
long = "format",
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
default_value = "long"
long,
possible_values(&Format::variants()),
case_insensitive(true),
default_value("long")
)]
pub format: Format,

Expand All @@ -70,30 +71,22 @@ struct Args {
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub struct FileArgs {
#[structopt(long, raw(overrides_with = r#""check-filenames""#))]
#[structopt(long, overrides_with("check-filenames"))]
/// Skip verifying spelling in file names.
no_check_filenames: bool,
#[structopt(
long,
raw(overrides_with = r#""no-check-filenames""#),
raw(hidden = "true")
)]
#[structopt(long, overrides_with("no-check-filenames"), hidden(true))]
check_filenames: bool,

#[structopt(long, raw(overrides_with = r#""check-files""#))]
#[structopt(long, overrides_with("check-files"))]
/// Skip verifying spelling in filess.
no_check_files: bool,
#[structopt(
long,
raw(overrides_with = r#""no-check-files""#),
raw(hidden = "true")
)]
#[structopt(long, overrides_with("no-check-files"), hidden(true))]
check_files: bool,

#[structopt(long, raw(overrides_with = r#""hex""#))]
#[structopt(long, overrides_with("hex"))]
/// Don't try to detect that an identifier looks like hex
no_hex: bool,
#[structopt(long, raw(overrides_with = r#""no-hex""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("no-hex"), hidden(true))]
hex: bool,
}

Expand Down Expand Up @@ -142,54 +135,46 @@ impl config::ConfigSource for ConfigArgs {
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
struct WalkArgs {
#[structopt(long, raw(overrides_with = r#""no-binary""#))]
#[structopt(long, overrides_with("no-binary"))]
/// Search binary files.
binary: bool,
#[structopt(long, raw(overrides_with = r#""binary""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("binary"), hidden(true))]
no_binary: bool,

#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
#[structopt(long, overrides_with("no-hidden"))]
/// Search hidden files and directories.
hidden: bool,
#[structopt(long, raw(overrides_with = r#""hidden""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("hidden"), hidden(true))]
no_hidden: bool,

#[structopt(long, raw(overrides_with = r#""ignore""#))]
#[structopt(long, overrides_with("ignore"))]
/// Don't respect ignore files.
no_ignore: bool,
#[structopt(long, raw(overrides_with = r#""no-ignore""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("no-ignore"), hidden(true))]
ignore: bool,

#[structopt(long, raw(overrides_with = r#""ignore-dot""#))]
#[structopt(long, overrides_with("ignore-dot"))]
/// Don't respect .ignore files.
no_ignore_dot: bool,
#[structopt(long, raw(overrides_with = r#""no-ignore-dot""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("no-ignore-dot"), hidden(true))]
ignore_dot: bool,

#[structopt(long, raw(overrides_with = r#""ignore-global""#))]
#[structopt(long, overrides_with("ignore-global"))]
/// Don't respect global ignore files.
no_ignore_global: bool,
#[structopt(
long,
raw(overrides_with = r#""no-ignore-global""#),
raw(hidden = "true")
)]
#[structopt(long, overrides_with("no-ignore-global"), hidden(true))]
ignore_global: bool,

#[structopt(long, raw(overrides_with = r#""ignore-parent""#))]
#[structopt(long, overrides_with("ignore-parent"))]
/// Don't respect ignore files in parent directories.
no_ignore_parent: bool,
#[structopt(
long,
raw(overrides_with = r#""no-ignore-parent""#),
raw(hidden = "true")
)]
#[structopt(long, overrides_with("no-ignore-parent"), hidden(true))]
ignore_parent: bool,

#[structopt(long, raw(overrides_with = r#""ignore-vcs""#))]
#[structopt(long, overrides_with("ignore-vcs"))]
/// Don't respect ignore files in vcs directories.
no_ignore_vcs: bool,
#[structopt(long, raw(overrides_with = r#""no-ignore-vcs""#), raw(hidden = "true"))]
#[structopt(long, overrides_with("no-ignore-vcs"), hidden(true))]
ignore_vcs: bool,
}

Expand Down Expand Up @@ -258,32 +243,33 @@ impl config::WalkSource for WalkArgs {
}
}

pub fn get_logging(level: log::Level) -> env_logger::Builder {
let mut builder = env_logger::Builder::new();
pub fn init_logging(level: Option<log::Level>) {
if let Some(level) = level {
let mut builder = env_logger::Builder::new();

builder.filter(None, level.to_level_filter());
builder.filter(None, level.to_level_filter());

if level == log::LevelFilter::Trace {
builder.default_format_timestamp(false);
} else {
builder.format(|f, record| {
writeln!(
f,
"[{}] {}",
record.level().to_string().to_lowercase(),
record.args()
)
});
}
if level == log::LevelFilter::Trace {
builder.default_format_timestamp(false);
} else {
builder.format(|f, record| {
writeln!(
f,
"[{}] {}",
record.level().to_string().to_lowercase(),
record.args()
)
});
}

builder
builder.init();
}
}

fn run() -> Result<i32, failure::Error> {
let args = Args::from_args();

let mut builder = get_logging(args.verbose.log_level());
builder.init();
init_logging(args.verbose.log_level());

let mut config = config::Config::default();
if let Some(path) = args.custom_config.as_ref() {
Expand Down

0 comments on commit 5e6e4b9

Please sign in to comment.