Skip to content

Commit

Permalink
Merge pull request #9 from Chuckame/feat/add-verbose-apply-param
Browse files Browse the repository at this point in the history
Added verbose mode for apply command
  • Loading branch information
Chuckame authored Feb 11, 2021
2 parents fd6b70c + 6c6205b commit a49b2fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ Usage: marlin-console-configurator [command] [command options]
--save, -s
When is present, will save changes to files. Else, just display changes without saving
Default: false
--verbose, -v
when present, all non-changed line are printed
Default: false
--yes, -y
when present, the changes will be saved without prompting the user
Default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ApplyCommand implements Command {
private boolean doSave;
@Parameter(names = {"--yes", "-y"}, description = "when present, the changes will be saved without prompting the user")
private boolean applyWithoutPrompt;
@Parameter(names = {"--verbose", "-v"}, description = "when present, all non-changed line are printed")
private boolean verbose;

private final ProfileAdapter profileAdapter;
private final LineChangeManager lineChangeManager;
Expand Down Expand Up @@ -71,17 +73,19 @@ private Mono<Map<Path, List<LineChange>>> prepareChanges(final Map<String, Const
private Mono<Void> printChanges(final Map<Path, List<LineChange>> changes) {
return Flux.fromIterable(changes.entrySet())
.concatMap(fileChanges -> Flux.concat(
Mono.fromRunnable(() -> consoleHelper
.writeLine(String.format("%s change(s) to apply for file %s:", fileChanges.getValue().stream().filter(this::isModifyingChange)
.count(), fileChanges
.getKey()), ConsoleHelper.FormatterEnum.UNDERLINED, ConsoleHelper.FormatterEnum.BOLD, ConsoleHelper.ForegroundColorEnum.GREEN)),
Flux.fromIterable(fileChanges.getValue())
.filter(this::isModifyingChange)
.count()
.filter(count -> verbose || count > 0)
.doOnNext(count -> consoleHelper.writeLine(String.format("%s change(s) to apply for file %s:", count, fileChanges
.getKey()), ConsoleHelper.FormatterEnum.UNDERLINED, ConsoleHelper.FormatterEnum.BOLD, ConsoleHelper.ForegroundColorEnum.GREEN)),
Flux.fromIterable(fileChanges.getValue())
.filter(LineChange::isConstant)
.filter(c -> c.getDiff() != LineChange.DiffEnum.DO_NOTHING)
.filter(this::isModifyingChange)
.doOnNext(change -> consoleHelper.writeLine(lineChangeFormatter.format(change), getChangeColor(change))),
Flux.fromIterable(fileChanges.getValue())
.filter(LineChange::isConstant)
.filter(c -> c.getDiff() == LineChange.DiffEnum.DO_NOTHING)
.filter(c -> verbose && !isModifyingChange(c))
.doOnNext(change -> consoleHelper.writeLine(lineChangeFormatter.format(change), getChangeColor(change))),
Mono.fromRunnable(consoleHelper::newLine)
))
Expand Down

0 comments on commit a49b2fe

Please sign in to comment.