@@ -16,7 +16,6 @@ import { downloadHook, getAllHooksName } from "../utils/downloadHook";
1616const addOptionsSchema = z . object ( {
1717 hooks : z . array ( z . string ( ) ) . optional ( ) ,
1818 overwrite : z . boolean ( ) ,
19- cwd : z . string ( ) ,
2019 all : z . boolean ( ) ,
2120 path : z . string ( ) . optional ( ) ,
2221} ) ;
@@ -26,11 +25,6 @@ export const add = new Command()
2625 . description ( "add a hook to your project" )
2726 . argument ( "[hooks...]" , "the hooks to add" )
2827 . option ( "-o, --overwrite" , "overwrite existing files." , false )
29- . option (
30- "-c, --cwd <cwd>" ,
31- "the working directory. defaults to the current directory." ,
32- process . cwd ( )
33- )
3428 . option ( "-a, --all" , "add all available hooks" , false )
3529 . option ( "-p, --path <path>" , "the path to add the hook to." )
3630 . action ( async ( hooks , opts ) => {
@@ -39,13 +33,7 @@ export const add = new Command()
3933 ...opts ,
4034 } ) ;
4135
42- const cwd = path . resolve ( options . cwd ) ;
43-
44- if ( ! existsSync ( cwd ) ) {
45- logger . error ( `The path ${ cwd } does not exist. Please try again.` ) ;
46- process . exit ( 1 ) ;
47- }
48-
36+ // Handle hooks selection
4937 const allHooks = await getAllHooksName ( ) ;
5038
5139 let selectedHooks = options . all ? allHooks : options . hooks ;
@@ -71,8 +59,29 @@ export const add = new Command()
7159 process . exit ( 0 ) ;
7260 }
7361
62+ // Handle path selection
63+ let selectedPath = options . path ?? "" ;
64+
65+ if ( selectedPath === "" ) {
66+ const { path } = await prompts ( {
67+ type : "text" ,
68+ name : "path" ,
69+ message : "Where would you like to add the hooks?" ,
70+ instructions : false ,
71+ } ) ;
72+
73+ selectedPath = path ;
74+ }
75+
76+ if ( ! existsSync ( selectedPath ) ) {
77+ logger . error (
78+ `The path ${ selectedPath } does not exist. Please try again.`
79+ ) ;
80+ process . exit ( 1 ) ;
81+ }
82+
7483 for ( let i = 0 ; i < selectedHooks . length ; i ++ ) {
7584 const hook = selectedHooks [ i ] ;
76- await downloadHook ( hook ) ;
85+ await downloadHook ( hook , selectedPath ) ;
7786 }
7887 } ) ;
0 commit comments