File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,30 @@ var rmCmd = &cobra.Command{
2424 return err
2525 }
2626
27+ force , _ := cmd .Flags ().GetBool ("force" )
28+
2729 // Check if anything depends on this
2830 felts , err := storage .List ()
2931 if err != nil {
3032 return err
3133 }
3234 for _ , other := range felts {
3335 if other .DependsOn .HasID (f .ID ) {
34- return fmt .Errorf ("cannot delete: %s depends on this felt" , other .ID )
36+ if ! force {
37+ return fmt .Errorf ("cannot delete: %s depends on this felt" , other .ID )
38+ }
39+ // Auto-unlink
40+ var newDeps felt.Dependencies
41+ for _ , d := range other .DependsOn {
42+ if d .ID != f .ID {
43+ newDeps = append (newDeps , d )
44+ }
45+ }
46+ other .DependsOn = newDeps
47+ if err := storage .Write (other ); err != nil {
48+ return fmt .Errorf ("unlinking %s: %w" , other .ID , err )
49+ }
50+ fmt .Printf ("Unlinked %s → %s\n " , other .ID , f .ID )
3551 }
3652 }
3753
@@ -46,4 +62,5 @@ var rmCmd = &cobra.Command{
4662
4763func init () {
4864 rootCmd .AddCommand (rmCmd )
65+ rmCmd .Flags ().BoolP ("force" , "f" , false , "Auto-unlink dependents before deleting" )
4966}
You can’t perform that action at this time.
0 commit comments