@@ -170,3 +170,34 @@ test('when requiredOption with implied value then not throw', () => {
170170 program . parse ( [ '--default-target' ] , { from : 'user' } ) ;
171171 } ) . not . toThrow ( ) ;
172172} ) ;
173+
174+ test ( 'when implies on program and use subcommand then program updated' , ( ) => {
175+ const program = new Command ( ) ;
176+ program
177+ . addOption ( new Option ( '--foo' ) . implies ( { bar : 'implied' } ) ) ;
178+ program
179+ . command ( 'sub' )
180+ . action ( ( ) => { } ) ;
181+ program . parse ( [ '--foo' , 'sub' ] , { from : 'user' } ) ;
182+ expect ( program . opts ( ) . bar ) . toEqual ( 'implied' ) ;
183+ } ) ;
184+
185+ test ( 'when option with implies used multiple times then implied gets single value' , ( ) => {
186+ const program = new Command ( ) ;
187+ program
188+ . addOption ( new Option ( '--foo' ) . implies ( { bar : 'implied' } ) )
189+ . option ( '-b, --bar <value...>' ) ;
190+ program . parse ( [ '--foo' , '--foo' ] , { from : 'user' } ) ;
191+ expect ( program . opts ( ) . bar ) . toEqual ( 'implied' ) ;
192+ } ) ;
193+
194+ test ( 'when implied option has custom processing then custom processing not called' , ( ) => {
195+ let called = false ;
196+ const program = new Command ( ) ;
197+ program
198+ . addOption ( new Option ( '--foo' ) . implies ( { bar : true } ) )
199+ . option ( '-b, --bar' , 'description' , ( ) => { called = true ; } ) ;
200+ program . parse ( [ '--foo' ] , { from : 'user' } ) ;
201+ expect ( program . opts ( ) . bar ) . toEqual ( true ) ;
202+ expect ( called ) . toEqual ( false ) ;
203+ } ) ;
0 commit comments