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

Added dry-run mode command line option (-n, --dry-run). #283

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ OPTIONS:
-d, --deletion-chunk-size <DELETION CHUNK SIZE>
Removes specified quantity of images at a time (default: 1)

-n, --dry-run
Dry run mode, prevents deletion of any images.

-h, --help
Prints help information

Expand Down
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const DEFAULT_THRESHOLD: &str = "10 GB";
// Command-line argument and option names
const DELETION_CHUNK_SIZE_OPTION: &str = "deletion-chunk-size";
const KEEP_OPTION: &str = "keep";
const DRY_RUN_OPTION: &str = "dry-run";
const THRESHOLD_OPTION: &str = "threshold";

// Size threshold argument, absolute or relative to filesystem size
Expand Down Expand Up @@ -109,6 +110,7 @@ pub struct Settings {
threshold: Threshold,
keep: Option<RegexSet>,
deletion_chunk_size: usize,
dry_run: bool,
}

// Set up the logger.
Expand Down Expand Up @@ -186,6 +188,14 @@ fn settings() -> io::Result<Settings> {
.number_of_values(1)
.help("Prevents deletion of images for which repository:tag matches <REGEX>"),
)
.arg(
Arg::with_name(DRY_RUN_OPTION)
.short("n")
.long(DRY_RUN_OPTION)
.required(false)
.takes_value(false)
.help("Dry run mode, prevents deletion of any images."),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other flag descriptions, don't punctuate as a sentence

                .help("Dry run mode, prevents deletion of any images"),

)
.arg(
Arg::with_name(DELETION_CHUNK_SIZE_OPTION)
.value_name("DELETION CHUNK SIZE")
Expand Down Expand Up @@ -216,6 +226,11 @@ fn settings() -> io::Result<Settings> {
None => None,
};

let dry_run = matches.is_present(DRY_RUN_OPTION);
if dry_run {
info!("Dry-run mode enabled, will not be deleting images.");
}

// Determine how many images to delete at once.
let deletion_chunk_size = match matches.value_of(DELETION_CHUNK_SIZE_OPTION) {
Some(v) => match v.parse::<usize>() {
Expand All @@ -229,6 +244,7 @@ fn settings() -> io::Result<Settings> {
threshold,
keep,
deletion_chunk_size,
dry_run,
})
}

Expand Down
Loading
Loading