11import { BitError } from '@teambit/bit-error' ;
22import chalk from 'chalk' ;
3+ import yesno from 'yesno' ;
34import type { Command , CommandOptions } from '@teambit/cli' ;
45import { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants' ;
56import type { SnappingMain } from './snapping.main.runtime' ;
@@ -15,11 +16,12 @@ export default class ResetCmd implements Command {
1516 ] ;
1617 group = 'version-control' ;
1718 extendedDescription = `removes local component versions (tags/snaps) that haven't been exported yet.
18- by default reverts all local versions. use --head to revert only the latest version.
19+ if no component-pattern is provided, resets all components (with confirmation prompt).
20+ by default reverts all local versions of each component. use --head to revert only the latest version.
1921useful for undoing mistakes before exporting. exported versions cannot be reset.` ;
2022 alias = '' ;
2123 options = [
22- [ 'a' , 'all' , 'revert all unexported tags/snaps for all components ' ] ,
24+ [ 'a' , 'all' , 'DEPRECATED. this is now the default behavior when no component-pattern is provided ' ] ,
2325 [ '' , 'head' , 'revert the head tag/snap only (by default, all local tags/snaps are reverted)' ] ,
2426 [ '' , 'soft' , 'revert only soft-tags (components tagged with --soft flag)' ] ,
2527 [
@@ -28,6 +30,7 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
2830 "revert the tag even if it's used as a dependency. WARNING: components that depend on this tag will be corrupted" ,
2931 ] ,
3032 [ '' , 'never-exported' , 'reset only components that were never exported' ] ,
33+ [ 's' , 'silent' , 'skip confirmation when resetting all components' ] ,
3134 ] as CommandOptions ;
3235 loader = true ;
3336
@@ -40,22 +43,21 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
4043 head = false ,
4144 force = false ,
4245 soft = false ,
46+ silent = false ,
4347 neverExported = false ,
44- } : { all ?: boolean ; head ?: boolean ; force ?: boolean ; soft ?: boolean ; neverExported ?: boolean }
48+ } : { all ?: boolean ; head ?: boolean ; force ?: boolean ; soft ?: boolean ; silent ?: boolean ; neverExported ?: boolean }
4549 ) {
4650 if ( neverExported ) {
4751 const compIds = await this . snapping . resetNeverExported ( ) ;
4852 return chalk . green ( `successfully reset the following never-exported components:\n${ compIds . join ( '\n' ) } ` ) ;
4953 }
50- if ( ! pattern && ! all ) {
51- throw new BitError ( 'please specify a component-pattern or use --all flag' ) ;
52- }
53- if ( pattern && all ) {
54- throw new BitError ( 'please specify either a component-pattern or --all flag, not both' ) ;
55- }
5654 if ( soft && head ) {
5755 throw new BitError ( 'please specify either --soft or --head flag, not both' ) ;
5856 }
57+ // if no pattern provided, reset all components (with confirmation unless --silent or --all)
58+ if ( ! pattern && ! silent && ! all ) {
59+ await this . promptForResetAll ( ) ;
60+ }
5961 const { results, isSoftUntag } = await this . snapping . reset ( pattern , head , force , soft ) ;
6062 const titleSuffix = isSoftUntag ? 'soft-untagged (are not candidates for tagging any more)' : 'reset' ;
6163 const title = chalk . green ( `${ results . length } component(s) were ${ titleSuffix } :\n` ) ;
@@ -64,4 +66,14 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
6466 } ) ;
6567 return title + components . join ( '\n' ) ;
6668 }
69+
70+ private async promptForResetAll ( ) {
71+ this . snapping . logger . clearStatusLine ( ) ;
72+ const ok = await yesno ( {
73+ question : `${ chalk . bold ( 'This will reset all local tags/snaps for all components. Would you like to proceed? [yes(y)/no(n)]' ) } ` ,
74+ } ) ;
75+ if ( ! ok ) {
76+ throw new BitError ( 'the operation has been canceled' ) ;
77+ }
78+ }
6779}
0 commit comments