1- import {
2- colors ,
3- Command ,
4- log ,
5- yamlStringify ,
6- Confirm ,
7- } from "../../../deps.ts" ;
1+ import { colors , Command , log , yamlStringify , Confirm } from "../../../deps.ts" ;
82import { GlobalOptions } from "../../types.ts" ;
93import { readLockfile } from "../../utils/metadata.ts" ;
104import { SCRIPT_GUIDANCE } from "../../guidance/script_guidance.ts" ;
115import { FLOW_GUIDANCE } from "../../guidance/flow_guidance.ts" ;
6+ import { getActiveWorkspaceOrFallback } from "../workspace/workspace.ts" ;
127
138export interface InitOptions {
149 useDefault ?: boolean ;
@@ -61,23 +56,21 @@ async function initAction(opts: InitOptions) {
6156
6257 // Offer to bind workspace profile to current branch
6358 if ( isGitRepository ( ) ) {
64- const { getActiveWorkspace } = await import ( "../workspace/workspace.ts" ) ;
65- const activeWorkspace = await getActiveWorkspace (
59+ const activeWorkspace = await getActiveWorkspaceOrFallback (
6660 opts as GlobalOptions
6761 ) ;
6862 const currentBranch = getCurrentGitBranch ( ) ;
69-
7063 if ( activeWorkspace && currentBranch ) {
7164 // Determine binding behavior based on flags
7265 const shouldBind = opts . bindProfile === true ;
7366 const shouldPrompt =
7467 opts . bindProfile === undefined &&
7568 Deno . stdin . isTerminal ( ) &&
7669 ! opts . useDefault ;
70+
7771 const shouldSkip =
78- opts . bindProfile === false ||
79- opts . useDefault ||
80- ( ! Deno . stdin . isTerminal ( ) && opts . bindProfile === undefined ) ;
72+ opts . bindProfile != true &&
73+ ( opts . useDefault || ! Deno . stdin . isTerminal ( ) ) ;
8174
8275 if ( shouldSkip ) {
8376 return ;
@@ -86,15 +79,11 @@ async function initAction(opts: InitOptions) {
8679 // Show workspace info if we're binding or prompting
8780 if ( shouldBind || shouldPrompt ) {
8881 log . info (
89- colors . yellow (
90- `\nCurrent Git branch: ${ colors . bold ( currentBranch ) } `
91- )
82+ colors . yellow ( `\nCurrent Git branch: ${ colors . bold ( currentBranch ) } ` )
9283 ) ;
9384 log . info (
9485 colors . yellow (
95- `Active workspace profile: ${ colors . bold (
96- activeWorkspace . name
97- ) } `
86+ `Active workspace profile: ${ colors . bold ( activeWorkspace . name ) } `
9887 )
9988 ) ;
10089 log . info (
@@ -123,15 +112,15 @@ async function initAction(opts: InitOptions) {
123112 currentConfig . gitBranches [ currentBranch ] = { overrides : { } } ;
124113 }
125114
115+ log . info (
116+ `binding branch ${ currentBranch } to workspace ${ activeWorkspace . name } on ${ activeWorkspace . remote } `
117+ ) ;
126118 currentConfig . gitBranches [ currentBranch ] . baseUrl =
127119 activeWorkspace . remote ;
128120 currentConfig . gitBranches [ currentBranch ] . workspaceId =
129121 activeWorkspace . workspaceId ;
130122
131- await Deno . writeTextFile (
132- "wmill.yaml" ,
133- yamlStringify ( currentConfig )
134- ) ;
123+ await Deno . writeTextFile ( "wmill.yaml" , yamlStringify ( currentConfig ) ) ;
135124
136125 log . info (
137126 colors . green (
@@ -149,10 +138,10 @@ async function initAction(opts: InitOptions) {
149138 const { resolveWorkspace } = await import ( "../../core/context.ts" ) ;
150139
151140 // Check if user has workspace configured
152- const { getActiveWorkspace } = await import ( "../workspace/workspace.ts" ) ;
153- const activeWorkspace = await getActiveWorkspace (
154- opts as GlobalOptions
141+ const { getActiveWorkspace } = await import (
142+ "../workspace/workspace.ts"
155143 ) ;
144+ const activeWorkspace = await getActiveWorkspace ( opts as GlobalOptions ) ;
156145
157146 if ( ! activeWorkspace ) {
158147 log . info ( "No workspace configured. Using default settings." ) ;
@@ -233,9 +222,7 @@ async function initAction(opts: InitOptions) {
233222 replace : true , // Auto-replace when using backend settings during init
234223 } ) ;
235224
236- log . info (
237- colors . green ( "Git-sync settings applied from backend" )
238- ) ;
225+ log . info ( colors . green ( "Git-sync settings applied from backend" ) ) ;
239226 }
240227 }
241228 } catch ( error ) {
@@ -266,10 +253,7 @@ async function initAction(opts: InitOptions) {
266253 }
267254
268255 if ( ! ( await Deno . stat ( ".cursor/rules/flow.mdc" ) . catch ( ( ) => null ) ) ) {
269- await Deno . writeTextFile (
270- ".cursor/rules/flow.mdc" ,
271- flowGuidanceContent
272- ) ;
256+ await Deno . writeTextFile ( ".cursor/rules/flow.mdc" , flowGuidanceContent ) ;
273257 log . info ( colors . green ( "Created .cursor/rules/flow.mdc" ) ) ;
274258 }
275259
0 commit comments