From ae10b53ae231a36c0259a2ca3fe10402c5c846de Mon Sep 17 00:00:00 2001 From: plastikfan Date: Fri, 16 Feb 2024 12:52:32 +0000 Subject: [PATCH] fix(command): make cuddle incompatible with both trash and output (#172) --- src/app/command/shrink-cmd.go | 15 ++++++++ src/app/command/shrink-cmd_test.go | 46 +++++++++++++++++++----- src/app/proxy/filing/path-finder_test.go | 33 +++++++++++++++++ 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/src/app/command/shrink-cmd.go b/src/app/command/shrink-cmd.go index 2c4ba26..3eda3db 100644 --- a/src/app/command/shrink-cmd.go +++ b/src/app/command/shrink-cmd.go @@ -348,6 +348,21 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob // // shrinkCommand.Args = validatePositionalArgs + // If we allowed --output to be specified with --cuddle, then that would + // mean the result files would be written to the output location and then input + // files would have to follow the results, leaving the origin without + // the input or the output. This could be seen as excessive and unnecessary. + // The cuddle option is most useful to the user when running a sample to + // enable easier comparison of the result with the input. If the user + // really wants to cuddle, then there should be no need to specify an output. + // We need to reduce the number of permutations to reduce complexity and + // the number of required unit tests; particularly for the path-finder. + // The same logic applies to cuddle with trash, except that's its even more + // acute in this usage scenario, because you never want your new results + // to be cuddled into the trash location. + paramSet.Command.MarkFlagsMutuallyExclusive("output", "cuddle") + paramSet.Command.MarkFlagsMutuallyExclusive("trash", "cuddle") + return shrinkCommand } diff --git a/src/app/command/shrink-cmd_test.go b/src/app/command/shrink-cmd_test.go index 2dc579b..8f03c74 100644 --- a/src/app/command/shrink-cmd_test.go +++ b/src/app/command/shrink-cmd_test.go @@ -31,6 +31,7 @@ type commandTE struct { outputFlag string outputValue string configPath string + expectError bool } type shrinkTE struct { @@ -38,7 +39,7 @@ type shrinkTE struct { directory string } -func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) { +func assertShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) { bootstrap := command.Bootstrap{ Vfs: vfs, } @@ -69,9 +70,16 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root } _, err := tester.Execute() - Expect(err).Error().To(BeNil(), - "should pass validation due to all flag being valid", - ) + + if entry.expectError { + Expect(err).Error().NotTo(BeNil(), + "expected error due to invalid flag combination", + ) + } else { + Expect(err).Error().To(BeNil(), + "should pass validation due to all flag being valid", + ) + } } var _ = Describe("ShrinkCmd", Ordered, func() { @@ -99,7 +107,8 @@ var _ = Describe("ShrinkCmd", Ordered, func() { func(entry *shrinkTE) { entry.directory = BackyardWorldsPlanet9Scan01 entry.configPath = configPath - expectValidShrinkCmdInvocation(vfs, entry, root) + + assertShrinkCmdInvocation(vfs, entry, root) }, func(entry *shrinkTE) string { return fmt.Sprintf("๐Ÿงช ===> given: '%v'", entry.message) @@ -242,6 +251,25 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, }), + Entry(nil, &shrinkTE{ + commandTE: commandTE{ + message: "expect error since cuddle not compatible with output", + expectError: true, + args: []string{ + "--cuddle", "--output", "results", + }, + }, + }), + + Entry(nil, &shrinkTE{ + commandTE: commandTE{ + message: "expect error since cuddle not compatible with trash", + expectError: true, + args: []string{ + "--cuddle", "--trash", "results", + }, + }, + }), // <---- ) @@ -261,7 +289,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + assertShrinkCmdInvocation(vfs, entry, root) }) It("๐Ÿงช should: execute successfully", func() { @@ -276,7 +304,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + assertShrinkCmdInvocation(vfs, entry, root) }) }) @@ -293,7 +321,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + assertShrinkCmdInvocation(vfs, entry, root) }) It("๐Ÿงช should: execute successfully", func() { @@ -308,7 +336,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + assertShrinkCmdInvocation(vfs, entry, root) }) }) }) diff --git a/src/app/proxy/filing/path-finder_test.go b/src/app/proxy/filing/path-finder_test.go index bcbcc7a..3ff0543 100644 --- a/src/app/proxy/filing/path-finder_test.go +++ b/src/app/proxy/filing/path-finder_test.go @@ -325,6 +325,39 @@ var _ = Describe("PathFinder", Ordered, func() { }, }), + // + // === TRANSPARENT / ADHOC + // + Entry(nil, &pfTE{ + given: "๐ŸŒ€ TRANSFER: transparent/adhoc/non-cuddled", + should: "redirect input to supplemented folder // filename not modified", + reasons: reasons{ + folder: "transparency, result should take place of input in same folder", + file: "file should be moved out of the way and not cuddled", + }, + supplements: supplements{ + folder: filepath.Join("$TRASH$", "ADHOC"), + }, + actionTransfer: true, + assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) { + Expect(folder).To(Equal(filepath.Join(pi.Origin, entry.supplements.folder)), because(entry.reasons.folder)) + Expect(file).To(Equal(pi.Item.Extension.Name), because(entry.reasons.file)) + }, + }), + + Entry(nil, &pfTE{ + given: "๐ŸŽ RESULT: transparent/adhoc", + should: "not modify folder // not modify filename", + reasons: reasons{ + folder: "transparency, result should take place of input", + file: "file should be moved out of the way and not cuddled", + }, + assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) { + Expect(folder).To(Equal(pi.Origin), because(entry.reasons.folder)) + Expect(file).To(Equal(pi.Item.Extension.Name), because(entry.reasons.file)) + }, + }), + // // NON-TRANSPARENT //