Class: VsClean::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- VsClean::Command
- Defined in:
- lib/commands/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collect_global_paths ⇒ Object
- #collect_local_paths ⇒ Object
- #delete(path) ⇒ Object
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #simulate_delete(path) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Command
Returns a new instance of Command.
19 20 21 22 23 |
# File 'lib/commands/command.rb', line 19 def initialize(argv) @dryrun = argv.flag?("dry-run") @global = argv.flag?("global") super end |
Class Method Details
.options ⇒ Object
12 13 14 15 16 17 |
# File 'lib/commands/command.rb', line 12 def self. [ ['[--global]', 'Delete global caches and temporary files'], ['[--dry-run]', 'Simulate deletion (list all files and directories that would be deleted)'] ].concat(super) end |
Instance Method Details
#collect_global_paths ⇒ Object
38 39 40 41 42 43 |
# File 'lib/commands/command.rb', line 38 def collect_global_paths home = File.("~") paths = Dir.glob(home + "/AppData/Local/JetBrains/**/SolutionCaches").select { |f| File.directory?(f) } paths.push(home + "/AppData/Microsoft/WebsiteCache") paths.push(*Dir.glob(home + "/AppData/Local/Microsoft/**/ComponentModelCache")) end |
#collect_local_paths ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/commands/command.rb', line 45 def collect_local_paths # bin and obj directories paths = Dir.glob("**/{bin,obj}").select { |f| File.directory?(f) } # .suo files (can cause Intellisense errors, solution load issues and more) paths.push(*Dir.glob("**/.vs/**/.suo")) end |
#delete(path) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/commands/command.rb', line 57 def delete(path) FileUtils.rm_r(path) Console.log_substep("Deleted '#{path}'") rescue StandardError => e Console.log_error("Could not delete '#{path}': #{e.message}") end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/commands/command.rb', line 25 def run paths = @global ? collect_global_paths : collect_local_paths if paths.none? Console.log_step("All good... nothing to clean!") return end Console.log_step("Cleaning...") paths.each { |d| @dryrun ? simulate_delete(d) : delete(d) } Console.log_step("Done!") end |
#simulate_delete(path) ⇒ Object
53 54 55 |
# File 'lib/commands/command.rb', line 53 def simulate_delete(path) Console.log_substep("Would delete '#{path}'") end |