11import * as path from "node:path" ;
22
33import { Flags } from "@oclif/core" ;
4+ import * as fs from "fs-extra" ;
45
56import BaseCommand from "@/lib/base-command" ;
67import * as CustomFlags from "@/lib/helpers/flag" ;
78import { DirContext } from "@/lib/helpers/fs" ;
9+ import { resolveKnockDir } from "@/lib/helpers/project-config" ;
810import { promptToConfirm } from "@/lib/helpers/ux" ;
911import {
1012 ALL_RESOURCE_TYPES ,
@@ -31,7 +33,7 @@ export default class Pull extends BaseCommand<typeof Pull> {
3133 branch : CustomFlags . branch ,
3234 "knock-dir" : CustomFlags . dirPath ( {
3335 summary : "The target directory path to pull all resources into." ,
34- required : true ,
36+ required : false ,
3537 } ) ,
3638 "hide-uncommitted-changes" : Flags . boolean ( {
3739 summary : "Hide any uncommitted changes." ,
@@ -43,7 +45,30 @@ export default class Pull extends BaseCommand<typeof Pull> {
4345
4446 public async run ( ) : Promise < void > {
4547 const { flags } = this . props ;
46- const targetDirCtx = flags [ "knock-dir" ] ;
48+
49+ // Resolve knock directory: flag takes precedence, otherwise use knock.json
50+ const knockDirPath = resolveKnockDir (
51+ flags [ "knock-dir" ] ?. abspath ,
52+ this . projectConfig ,
53+ ) ;
54+
55+ if ( ! knockDirPath ) {
56+ this . error (
57+ "No knock directory specified. Either provide --knock-dir flag or run `knock init` to create a knock.json configuration file." ,
58+ ) ;
59+ }
60+
61+ // Convert knockDirPath to DirContext
62+ const abspath = path . isAbsolute ( knockDirPath )
63+ ? knockDirPath
64+ : path . resolve ( process . cwd ( ) , knockDirPath ) ;
65+
66+ const exists = await fs . pathExists ( abspath ) ;
67+ if ( exists && ! ( await fs . lstat ( abspath ) ) . isDirectory ( ) ) {
68+ this . error ( `${ knockDirPath } exists but is not a directory` ) ;
69+ }
70+
71+ const targetDirCtx : DirContext = { abspath, exists } ;
4772
4873 const prompt = targetDirCtx . exists
4974 ? `Pull latest resources into ${ targetDirCtx . abspath } ?\n This will overwrite the contents of this directory.`
0 commit comments