Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore file option #27

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ $ mix deps.audit
| `--format` | String | `"human"` | The format of the report to generate (`"json"` or `"human"`) |
| `--ignore-advisory-ids` | String | `""` | Comma-separated list of advisory IDs to ignore |
| `--ignore-package-names` | String | `""` | Comma-separated list of package names to ignore |
| `--ignore-file` | String | `""` | Path of the ignore file |

## Example

Expand Down
1 change: 1 addition & 0 deletions lib/mix_audit/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule MixAudit.CLI do
switches: [
ignore_advisory_ids: :string,
ignore_package_names: :string,
ignore_file: :string,
version: :boolean,
help: :boolean,
format: :string,
Expand Down
20 changes: 20 additions & 0 deletions lib/mix_audit/cli/audit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@ defmodule MixAudit.CLI.Audit do
end

defp ignored_advisory_ids(opts) do
ignored_ids_from_cli = ignored_advisory_ids_from_cli(opts)
ignored_ids_from_file = ignored_advisory_ids_from_file(opts)

Enum.uniq(ignored_ids_from_cli ++ ignored_ids_from_file)
end

defp ignored_advisory_ids_from_cli(opts) do
opts
|> Keyword.get(:ignore_advisory_ids, "")
|> String.split(",")
|> Enum.map(&String.trim/1)
end

def ignored_advisory_ids_from_file(opts) do
case Keyword.get(opts, :ignore_file) do
nil ->
[]

ignore_file ->
ignore_file
|> File.read!()
|> String.split("\n")
|> Enum.reject(fn line -> String.starts_with?(line, "#") || String.trim(line) == "" end)
end
end

defp ignored_package_names(opts) do
opts
|> Keyword.get(:ignore_package_names, "")
Expand Down
1 change: 1 addition & 0 deletions lib/mix_audit/cli/help.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule MixAudit.CLI.Help do
IO.puts("--format The format of the report to generate (human, json)")
IO.puts("--ignore-advisory-ids A comma-separated list of advisory IDs to ignore")
IO.puts("--ignore-package-names A comma-separated list of package names to ignore")
IO.puts("--ignore-file Path of the ignore file")
IO.puts("")
System.halt(0)
end
Expand Down
Loading