Skip to content

Commit dbf25d8

Browse files
committed
Add clean-cache command
1 parent 9bd6905 commit dbf25d8

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Rewrite core functionality by using cached state instead of relying on the file system.
77
WARNING! this version is completely different functionally from the older one and the tags have to be recreated
88
after updating it. [#30](https://github.com/wojciechkepka/wutag/pull/30)
9+
* Add `clean-cache` subcommand that cleans the cached tag registry from the filesystem.
910

1011

1112
# 0.3.0

src/app.rs

+8
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ impl App {
101101
Command::Cp(ref opts) => self.cp(opts),
102102
Command::Edit(ref opts) => self.edit(opts),
103103
Command::PrintCompletions(ref opts) => self.print_completions(opts),
104+
Command::CleanCache => self.clean_cache(),
105+
}
106+
}
107+
108+
fn clean_cache(&mut self) {
109+
self.registry.clear();
110+
if let Err(e) = self.registry.save() {
111+
println!("{:?}", e);
104112
}
105113
}
106114

src/opt.rs

+2
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,6 @@ pub enum Command {
155155
Edit(EditOpts),
156156
/// Prints completions for the specified shell to stdout.
157157
PrintCompletions(CompletionsOpts),
158+
/// Clean the cached tag registry.
159+
CleanCache,
158160
}

src/registry.rs

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ impl TagRegistry {
5757
fs::write(&self.path, &serialized).context("failed to save registry")
5858
}
5959

60+
/// Clears this tag registry by removing all entries and tags.
61+
pub fn clear(&mut self) {
62+
self.tags.clear();
63+
self.entries.clear();
64+
}
65+
6066
/// Updates the entry or adds it if it is not present.
6167
pub fn add_or_update_entry(&mut self, entry: EntryData) -> EntryId {
6268
let pos = self

0 commit comments

Comments
 (0)