Skip to content

Commit dba68b1

Browse files
jonesphillippetebacondarwin
authored andcommitted
Now uses updateConfigFile to display workers/bindings instructions
1 parent 129b001 commit dba68b1

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

packages/wrangler/src/pipelines/cli/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const pipelinesCreateCommand = createCommand({
125125

126126
if (streamTable) {
127127
const stream = await getStream(config, streamTable.id);
128-
displayUsageExamples(stream, config);
128+
await displayUsageExamples(stream, config, args);
129129
} else {
130130
logger.log(
131131
`\nRun 'wrangler pipelines get ${pipeline.id}' to view full details.`

packages/wrangler/src/pipelines/cli/setup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const pipelinesSetupCommand = createCommand({
6767
await setupSinkConfiguration(config, setupConfig);
6868
const created = await reviewAndCreateStreamSink(config, setupConfig);
6969
await setupSQLTransformationWithValidation(config, setupConfig, created);
70-
await createPipelineIfNeeded(config, setupConfig, created);
70+
await createPipelineIfNeeded(config, setupConfig, created, args);
7171
} catch (error) {
7272
if (error instanceof UserError) {
7373
throw error;
@@ -778,7 +778,8 @@ async function reviewAndCreateStreamSink(
778778
async function createPipelineIfNeeded(
779779
config: Config,
780780
setupConfig: SetupConfig,
781-
created: { stream?: Stream; sink?: Sink }
781+
created: { stream?: Stream; sink?: Sink },
782+
args: { env?: string }
782783
): Promise<void> {
783784
if (!setupConfig.pipelineConfig) {
784785
throw new UserError("Pipeline configuration is missing");
@@ -792,7 +793,7 @@ async function createPipelineIfNeeded(
792793
logger.log("\n✨ Setup complete!");
793794

794795
if (created.stream) {
795-
displayUsageExamples(created.stream, config);
796+
await displayUsageExamples(created.stream, config, args);
796797
}
797798
} catch (error) {
798799
logger.error(

packages/wrangler/src/pipelines/cli/streams/utils.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatConfigSnippet } from "../../../config";
1+
import { updateConfigFile } from "../../../config";
22
import { logger } from "../../../logger";
33
import formatLabelledValues from "../../../utils/render-labelled-values";
44
import type { Config } from "../../../config";
@@ -205,7 +205,11 @@ function generateExampleData(stream: Stream): string {
205205
}
206206
}
207207

208-
export function displayUsageExamples(stream: Stream, config: Config) {
208+
export async function displayUsageExamples(
209+
stream: Stream,
210+
config: Config,
211+
args: { env?: string }
212+
) {
209213
const bindingName = generateStreamBindingName(stream.name);
210214
const exampleData = generateExampleData(stream);
211215

@@ -214,17 +218,19 @@ export function displayUsageExamples(stream: Stream, config: Config) {
214218
// Worker binding example (always shown since worker_binding is always enabled)
215219
logger.log("\nWorker Integration:");
216220

217-
const configSnippet = {
218-
pipelines: [
219-
{
220-
pipeline: stream.name,
221-
binding: bindingName,
222-
},
223-
],
224-
};
225-
226-
logger.log("Add to your configuration file:");
227-
logger.log(formatConfigSnippet(configSnippet, config.configPath));
221+
await updateConfigFile(
222+
(customBindingName) => ({
223+
pipelines: [
224+
{
225+
pipeline: stream.name,
226+
binding: customBindingName ?? bindingName,
227+
},
228+
],
229+
}),
230+
config.configPath,
231+
args.env,
232+
false // Don't offer to update automatically
233+
);
228234

229235
logger.log("\nIn your Worker:");
230236
logger.log(`await env.${bindingName}.send([${exampleData}]);`);

0 commit comments

Comments
 (0)