@@ -59,13 +59,10 @@ exports.Cluster = class Cluster {
59
59
*/
60
60
async installSource ( options = { } ) {
61
61
this . _log . info ( chalk . bold ( 'Installing from source' ) ) ;
62
- this . _log . indent ( 4 ) ;
63
-
64
- const { installPath } = await installSource ( { log : this . _log , ...options } ) ;
65
-
66
- this . _log . indent ( - 4 ) ;
67
-
68
- return { installPath } ;
62
+ return await this . _log . indent ( 4 , async ( ) => {
63
+ const { installPath } = await installSource ( { log : this . _log , ...options } ) ;
64
+ return { installPath } ;
65
+ } ) ;
69
66
}
70
67
71
68
/**
@@ -78,16 +75,14 @@ exports.Cluster = class Cluster {
78
75
*/
79
76
async downloadSnapshot ( options = { } ) {
80
77
this . _log . info ( chalk . bold ( 'Downloading snapshot' ) ) ;
81
- this . _log . indent ( 4 ) ;
78
+ return await this . _log . indent ( 4 , async ( ) => {
79
+ const { installPath } = await downloadSnapshot ( {
80
+ log : this . _log ,
81
+ ...options ,
82
+ } ) ;
82
83
83
- const { installPath } = await downloadSnapshot ( {
84
- log : this . _log ,
85
- ...options ,
84
+ return { installPath } ;
86
85
} ) ;
87
-
88
- this . _log . indent ( - 4 ) ;
89
-
90
- return { installPath } ;
91
86
}
92
87
93
88
/**
@@ -100,16 +95,14 @@ exports.Cluster = class Cluster {
100
95
*/
101
96
async installSnapshot ( options = { } ) {
102
97
this . _log . info ( chalk . bold ( 'Installing from snapshot' ) ) ;
103
- this . _log . indent ( 4 ) ;
98
+ return await this . _log . indent ( 4 , async ( ) => {
99
+ const { installPath } = await installSnapshot ( {
100
+ log : this . _log ,
101
+ ...options ,
102
+ } ) ;
104
103
105
- const { installPath } = await installSnapshot ( {
106
- log : this . _log ,
107
- ...options ,
104
+ return { installPath } ;
108
105
} ) ;
109
-
110
- this . _log . indent ( - 4 ) ;
111
-
112
- return { installPath } ;
113
106
}
114
107
115
108
/**
@@ -122,16 +115,14 @@ exports.Cluster = class Cluster {
122
115
*/
123
116
async installArchive ( path , options = { } ) {
124
117
this . _log . info ( chalk . bold ( 'Installing from an archive' ) ) ;
125
- this . _log . indent ( 4 ) ;
118
+ return await this . _log . indent ( 4 , async ( ) => {
119
+ const { installPath } = await installArchive ( path , {
120
+ log : this . _log ,
121
+ ...options ,
122
+ } ) ;
126
123
127
- const { installPath } = await installArchive ( path , {
128
- log : this . _log ,
129
- ...options ,
124
+ return { installPath } ;
130
125
} ) ;
131
-
132
- this . _log . indent ( - 4 ) ;
133
-
134
- return { installPath } ;
135
126
}
136
127
137
128
/**
@@ -144,21 +135,19 @@ exports.Cluster = class Cluster {
144
135
*/
145
136
async extractDataDirectory ( installPath , archivePath , extractDirName = 'data' ) {
146
137
this . _log . info ( chalk . bold ( `Extracting data directory` ) ) ;
147
- this . _log . indent ( 4 ) ;
148
-
149
- // stripComponents=1 excludes the root directory as that is how our archives are
150
- // structured. This works in our favor as we can explicitly extract into the data dir
151
- const extractPath = path . resolve ( installPath , extractDirName ) ;
152
- this . _log . info ( `Data archive : ${ archivePath } ` ) ;
153
- this . _log . info ( `Extract path: ${ extractPath } ` ) ;
154
-
155
- await extract ( {
156
- archivePath ,
157
- targetDir : extractPath ,
158
- stripComponents : 1 ,
138
+ await this . _log . indent ( 4 , async ( ) => {
139
+ // stripComponents=1 excludes the root directory as that is how our archives are
140
+ // structured. This works in our favor as we can explicitly extract into the data dir
141
+ const extractPath = path . resolve ( installPath , extractDirName ) ;
142
+ this . _log . info ( `Data archive: ${ archivePath } ` ) ;
143
+ this . _log . info ( `Extract path : ${ extractPath } ` ) ;
144
+
145
+ await extract ( {
146
+ archivePath ,
147
+ targetDir : extractPath ,
148
+ stripComponents : 1 ,
149
+ } ) ;
159
150
} ) ;
160
-
161
- this . _log . indent ( - 4 ) ;
162
151
}
163
152
164
153
/**
@@ -169,24 +158,27 @@ exports.Cluster = class Cluster {
169
158
* @returns {Promise<void> }
170
159
*/
171
160
async start ( installPath , options = { } ) {
172
- this . _exec ( installPath , options ) ;
173
-
174
- await Promise . race ( [
175
- // wait for native realm to be setup and es to be started
176
- Promise . all ( [
177
- first ( this . _process . stdout , ( data ) => {
178
- if ( / s t a r t e d / . test ( data ) ) {
179
- return true ;
180
- }
181
- } ) ,
182
- this . _setupPromise ,
183
- ] ) ,
161
+ // _exec indents and we wait for our own end condition, so reset the indent level to it's current state after we're done waiting
162
+ await this . _log . indent ( 0 , async ( ) => {
163
+ this . _exec ( installPath , options ) ;
164
+
165
+ await Promise . race ( [
166
+ // wait for native realm to be setup and es to be started
167
+ Promise . all ( [
168
+ first ( this . _process . stdout , ( data ) => {
169
+ if ( / s t a r t e d / . test ( data ) ) {
170
+ return true ;
171
+ }
172
+ } ) ,
173
+ this . _setupPromise ,
174
+ ] ) ,
184
175
185
- // await the outcome of the process in case it exits before starting
186
- this . _outcome . then ( ( ) => {
187
- throw createCliError ( 'ES exited without starting' ) ;
188
- } ) ,
189
- ] ) ;
176
+ // await the outcome of the process in case it exits before starting
177
+ this . _outcome . then ( ( ) => {
178
+ throw createCliError ( 'ES exited without starting' ) ;
179
+ } ) ,
180
+ ] ) ;
181
+ } ) ;
190
182
}
191
183
192
184
/**
@@ -197,16 +189,19 @@ exports.Cluster = class Cluster {
197
189
* @returns {Promise<void> }
198
190
*/
199
191
async run ( installPath , options = { } ) {
200
- this . _exec ( installPath , options ) ;
192
+ // _exec indents and we wait for our own end condition, so reset the indent level to it's current state after we're done waiting
193
+ await this . _log . indent ( 0 , async ( ) => {
194
+ this . _exec ( installPath , options ) ;
195
+
196
+ // log native realm setup errors so they aren't uncaught
197
+ this . _setupPromise . catch ( ( error ) => {
198
+ this . _log . error ( error ) ;
199
+ this . stop ( ) ;
200
+ } ) ;
201
201
202
- // log native realm setup errors so they aren't uncaught
203
- this . _setupPromise . catch ( ( error ) => {
204
- this . _log . error ( error ) ;
205
- this . stop ( ) ;
202
+ // await the final outcome of the process
203
+ await this . _outcome ;
206
204
} ) ;
207
-
208
- // await the final outcome of the process
209
- await this . _outcome ;
210
205
}
211
206
212
207
/**
0 commit comments