From 2aa5c2470d9cd16d7caa85414d87eaa784d00c15 Mon Sep 17 00:00:00 2001 From: Tony-Sol Date: Mon, 12 Jun 2023 04:27:40 +0300 Subject: [PATCH] Add group selection for dump command --- .gitignore | 3 +++ cmd/bundle.rb | 7 +++++++ lib/bundle/commands/dump.rb | 6 +++++- lib/bundle/dumper.rb | 25 ++++++++++++++++--------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 86498a09d..3045441dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea +.vscode + Brewfile Brewfile.lock.json Gemfile.lock diff --git a/cmd/bundle.rb b/cmd/bundle.rb index 00b3b21b1..35edce5bd 100755 --- a/cmd/bundle.rb +++ b/cmd/bundle.rb @@ -116,6 +116,13 @@ def bundle describe: args.describe?, force: args.force?, no_restart: args.no_restart?, + all: args.all?, + taps: args.taps?, + brews: args.brews?, + casks: args.casks?, + mas: args.mas?, + whalebrew: args.whalebrew?, + vscode: args.vscode?, ) when "cleanup" Bundle::Commands::Cleanup.run( diff --git a/lib/bundle/commands/dump.rb b/lib/bundle/commands/dump.rb index 8869b1f3c..5ede365d5 100644 --- a/lib/bundle/commands/dump.rb +++ b/lib/bundle/commands/dump.rb @@ -5,9 +5,13 @@ module Commands module Dump module_function - def run(global: false, file: nil, describe: false, force: false, no_restart: false) + def run(global: false, file: nil, describe: false, force: false, no_restart: false, + all: false, taps: false, brews: false, casks: false, + mas: false, whalebrew: false, vscode: false) Bundle::Dumper.dump_brewfile( global: global, file: file, describe: describe, force: force, no_restart: no_restart, + all: all, taps: taps, brews: brews, casks: casks, + mas: mas, whalebrew: whalebrew, vscode: vscode ) end end diff --git a/lib/bundle/dumper.rb b/lib/bundle/dumper.rb index 72c67f48d..72f88f469 100644 --- a/lib/bundle/dumper.rb +++ b/lib/bundle/dumper.rb @@ -13,21 +13,28 @@ def can_write_to_brewfile?(brewfile_path, force: false) true end - def build_brewfile(describe: false, no_restart: false) + def build_brewfile(describe: false, no_restart: false, + all: false, taps: false, brews: false, casks: false, + mas: false, whalebrew: false, vscode: false) + all ||= !(taps || brews || casks || mas || whalebrew || vscode) content = [] - content << TapDumper.dump - content << BrewDumper.dump(describe: describe, no_restart: no_restart) - content << CaskDumper.dump(describe: describe) - content << MacAppStoreDumper.dump - content << WhalebrewDumper.dump - content << VscodeExtensionDumper.dump + content << TapDumper.dump if taps || all + content << BrewDumper.dump(describe: describe, no_restart: no_restart) if brews || all + content << CaskDumper.dump(describe: describe) if casks || all + content << MacAppStoreDumper.dump if mas || all + content << WhalebrewDumper.dump if whalebrew || all + content << VscodeExtensionDumper.dump if vscode || all "#{content.reject(&:empty?).join("\n")}\n" end - def dump_brewfile(global: false, file: nil, describe: false, force: false, no_restart: false) + def dump_brewfile(global: false, file: nil, describe: false, force: false, no_restart: false, + all: false, taps: false, brews: false, casks: false, + mas: false, whalebrew: false, vscode: false) path = brewfile_path(global: global, file: file) can_write_to_brewfile?(path, force: force) - content = build_brewfile(describe: describe, no_restart: no_restart) + content = build_brewfile(describe: describe, no_restart: no_restart, + all: all, taps: taps, brews: brews, casks: casks, + mas: mas, whalebrew: whalebrew, vscode: vscode) write_file path, content end