Skip to content

Commit

Permalink
fix(push-data): passing the item via stdin works again (#617)
Browse files Browse the repository at this point in the history
Previously, doing `apify actor get-input | apify actor push-data` did not work. Now it does again.
  • Loading branch information
vladfrangu authored Aug 27, 2024
1 parent 8f92580 commit 4a855ec
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
11 changes: 1 addition & 10 deletions src/commands/actor/push-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,15 @@ export class PushDataCommand extends ApifyCommand<typeof PushDataCommand> {
}),
};

private stdin?: string;

override async init() {
await super.init();
// Read data from stdin of the command
this.stdin = await this.readStdin(process.stdin);
}

async run() {
const { item } = this.args;

const apifyClient = await getApifyStorageClient();
const defaultStoreId = getDefaultStorageId(APIFY_STORAGE_TYPES.DATASET);
const data = item || this.stdin;

let parsedData: Record<string, unknown> | Record<string, unknown>[];
try {
parsedData = JSON.parse(data!);
parsedData = JSON.parse(item!);
} catch (err) {
throw new Error(`Failed to parse data as JSON string: ${(err as Error).message}`);
}
Expand Down
8 changes: 0 additions & 8 deletions src/lib/apify_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import process from 'node:process';

import { Command, type Interfaces, loadHelpClass } from '@oclif/core';

import { readStdin } from './commands/read-stdin.js';
import { COMMANDS_WITHIN_ACTOR, LANGUAGE } from './consts.js';
import { maybeTrackTelemetry } from './telemetry.js';
import { type KeysToCamelCase, argsToCamelCase, detectLocalActorLanguage } from './utils.js';
Expand Down Expand Up @@ -73,13 +72,6 @@ export abstract class ApifyCommand<T extends typeof Command> extends Command {
return super.finally(err);
}

/**
* Reads data on standard input as a string.
*/
async readStdin(stdinStream: typeof process.stdin) {
return readStdin(stdinStream);
}

async printHelp(customCommand?: string) {
const HelpCommand = await loadHelpClass(this.config);
const help = new HelpCommand(this.config);
Expand Down

0 comments on commit 4a855ec

Please sign in to comment.