Skip to content

Commit

Permalink
Merge pull request #159 from jmcconnell26/ISSUE-151-AcceptReadmePathA…
Browse files Browse the repository at this point in the history
…ndSectionName

ISSUE-151 - Accept Readme Path and Section Name as parameters:
  • Loading branch information
anderejd committed Dec 11, 2020
2 parents db35ec7 + 8f3137f commit 91594c9
Show file tree
Hide file tree
Showing 17 changed files with 458 additions and 38 deletions.
28 changes: 21 additions & 7 deletions cargo-geiger/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ OPTIONS:
--format <FORMAT> Format string used for printing dependencies
[default: {p}].
--json Output in JSON format.
--update-readme Writes output to README.md. Looks for a Safety
--update-readme Writes output to ./README.md. Looks for a Safety
Report section, replaces if found, adds if not.
Throws an error if no README.md exists.
--readme-path <PATH> Path of README.md file to be written to.
--section-name <NAME> The section name in the README.md to be written
to.
-v, --verbose Use verbose output (-vv very verbose/build.rs
output).
-q, --quiet No output printed to stdout other than the
Expand All @@ -46,7 +49,7 @@ OPTIONS:
--locked Require Cargo.lock is up to date.
--offline Run without accessing the network.
-Z \"<FLAG>...\" Unstable (nightly-only) flags to Cargo.
--include-tests Count unsafe usage in tests..
--include-tests Count unsafe usage in tests.
--build-dependencies Also analyze build dependencies.
--dev-dependencies Also analyze dev dependencies.
--all-dependencies Analyze all dependencies, including build and
Expand Down Expand Up @@ -81,9 +84,9 @@ pub struct Args {
pub package: Option<String>,
pub prefix_depth: bool,
pub quiet: bool,
pub readme_args: ReadmeArgs,
pub target_args: TargetArgs,
pub unstable_flags: Vec<String>,
pub update_readme: bool,
pub verbose: u32,
pub version: bool,
pub output_format: Option<OutputFormat>,
Expand Down Expand Up @@ -133,6 +136,11 @@ impl Args {
package: raw_args.opt_value_from_str("--manifest-path")?,
prefix_depth: raw_args.contains("--prefix-depth"),
quiet: raw_args.contains(["-q", "--quiet"]),
readme_args: ReadmeArgs {
readme_path: raw_args.opt_value_from_str("--readme-path")?,
section_name: raw_args.opt_value_from_str("--section-name")?,
update_readme: raw_args.contains("--update-readme"),
},
target_args: TargetArgs {
all_targets: raw_args.contains("--all-targets"),
target: raw_args.opt_value_from_str("--target")?,
Expand All @@ -141,7 +149,6 @@ impl Args {
.opt_value_from_str("-Z")?
.map(|s: String| s.split(' ').map(|s| s.to_owned()).collect())
.unwrap_or_else(Vec::new),
update_readme: raw_args.contains("--update-readme"),
verbose: match (
raw_args.contains("-vv"),
raw_args.contains(["-v", "--verbose"]),
Expand Down Expand Up @@ -195,26 +202,33 @@ impl Args {
}
}

#[derive(Default)]
#[derive(Debug, Default)]
pub struct DepsArgs {
pub all_deps: bool,
pub build_deps: bool,
pub dev_deps: bool,
}

#[derive(Default)]
#[derive(Debug, Default)]
pub struct FeaturesArgs {
pub all_features: bool,
pub features: Vec<String>,
pub no_default_features: bool,
}

#[derive(Default)]
#[derive(Debug, Default)]
pub struct TargetArgs {
pub all_targets: bool,
pub target: Option<String>,
}

#[derive(Debug, Default)]
pub struct ReadmeArgs {
pub readme_path: Option<PathBuf>,
pub section_name: Option<String>,
pub update_readme: bool,
}

fn parse_features(raw_features: Option<String>) -> Vec<String> {
raw_features
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions cargo-geiger/src/format/emoji_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl EmojiSymbols {
Box::new(self.fallbacks[idx].clone())
}
}

pub fn new(charset: Charset) -> EmojiSymbols {
Self {
charset,
Expand Down
11 changes: 3 additions & 8 deletions cargo-geiger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use cargo_geiger::args::{Args, HELP};
use cargo_geiger::cli::{get_cargo_metadata, get_krates, get_workspace};
use cargo_geiger::graph::build_graph;
use cargo_geiger::mapping::{CargoMetadataParameters, QueryResolve};
use cargo_geiger::readme::{
create_or_replace_section_in_readme, README_FILENAME,
};
use cargo_geiger::readme::create_or_replace_section_in_readme;
use cargo_geiger::scan::{scan, FoundWarningsError, ScanResult};

use cargo::core::shell::Shell;
Expand Down Expand Up @@ -94,12 +92,9 @@ fn real_main(args: &Args, config: &mut Config) -> CliResult {
&workspace,
)?;

if args.update_readme {
let mut current_dir_path_buf = std::env::current_dir().unwrap();
current_dir_path_buf.push(README_FILENAME);

if args.readme_args.update_readme {
create_or_replace_section_in_readme(
current_dir_path_buf,
&args.readme_args,
&scan_output_lines,
)?;
} else {
Expand Down
Loading

0 comments on commit 91594c9

Please sign in to comment.