Skip to content

Commit

Permalink
fix: log info messages and warnings to stderr [fixes DXJ-416] (#358)
Browse files Browse the repository at this point in the history
* fix: log info messages and warnings to stderr [fixes DXJ-416]

* replace this.log for consistency
  • Loading branch information
shamsartem authored Jul 20, 2023
1 parent a35e53d commit 6156b56
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 32 deletions.
8 changes: 5 additions & 3 deletions src/commands/aqua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class Aqua extends Command {
if (!flags.watch) {
await compileToFiles(compileCommandArgs);

commandObj.log(
commandObj.logToStderr(
`Successfully compiled ${color.yellow(
compileCommandArgs.compileArgs.filePath,
)}${
Expand All @@ -177,7 +177,9 @@ export default class Aqua extends Command {
}

const watchingNotification = (): void => {
return this.log(`Watching for changes at ${color.yellow(inputFlag)}...`);
return commandObj.logToStderr(
`Watching for changes at ${color.yellow(inputFlag)}...`,
);
};

watchingNotification();
Expand All @@ -196,7 +198,7 @@ export default class Aqua extends Command {
watchingNotification();
})
.catch((error): void => {
commandObj.log(stringifyUnknown(error));
commandObj.logToStderr(stringifyUnknown(error));
return watchingNotification();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/aqua/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ export default class Json extends BaseCommand<typeof Json> {
FS_OPTIONS,
);

commandObj.log("Done!");
commandObj.logToStderr("Done!");
}
}
2 changes: 1 addition & 1 deletion src/commands/aqua/yml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ export default class Yaml extends BaseCommand<typeof Yaml> {
FS_OPTIONS,
);

commandObj.log("Done!");
commandObj.logToStderr("Done!");
}
}
2 changes: 1 addition & 1 deletion src/commands/deal/change-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ export default class ChangeApp extends BaseCommand<typeof ChangeApp> {
privKey: flags.privKey,
});

commandObj.log(`Tx hash: ${color.yellow(tx.hash)}`);
commandObj.logToStderr(`Tx hash: ${color.yellow(tx.hash)}`);
}
}
4 changes: 3 additions & 1 deletion src/commands/deal/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default class Create extends BaseCommand<typeof Create> {
}),
});

commandObj.log(`Deal contract created: ${color.yellow(dealAddress)}`);
commandObj.logToStderr(
`Deal contract created: ${color.yellow(dealAddress)}`,
);
}
}
6 changes: 3 additions & 3 deletions src/commands/deal/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class Deploy extends BaseCommand<typeof Deploy> {

if (maybePreviouslyDeployedDeal !== undefined) {
if (maybePreviouslyDeployedDeal.definition === appCID) {
commandObj.log(
commandObj.logToStderr(
`\nWorker ${color.yellow(
workerName,
)} didn't change. Skipping deal update`,
Expand All @@ -142,7 +142,7 @@ export default class Deploy extends BaseCommand<typeof Deploy> {
continue;
}

commandObj.log(
commandObj.logToStderr(
`\nUpdating deal for worker ${color.yellow(workerName)}\n`,
);

Expand Down Expand Up @@ -177,7 +177,7 @@ export default class Deploy extends BaseCommand<typeof Deploy> {
continue;
}

commandObj.log(
commandObj.logToStderr(
`\nCreating deal for worker ${color.yellow(workerName)}\n`,
);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependency/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export default class Install extends BaseCommand<typeof Install> {
force: flags.force,
});

commandObj.log("cargo and npm dependencies successfully installed");
commandObj.logToStderr("cargo and npm dependencies successfully installed");
}
}
2 changes: 1 addition & 1 deletion src/commands/key/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class Default extends BaseCommand<typeof Default> {
await projectSecretsConfig.$commit();
}

this.log(
commandObj.log(
`Key-pair with name ${color.yellow(
keyPairName,
)} successfully set as default at ${secretsConfigPath}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/key/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class New extends BaseCommand<typeof New> {
? userSecretsConfig.$commit()
: projectSecretsConfig.$commit());

this.log(
commandObj.log(
`Key-pair with name ${color.yellow(
keyPairName,
)} successfully generated and saved to ${secretsConfigPath}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/key/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class Remove extends BaseCommand<typeof Remove> {
await projectSecretsConfig.$commit();
}

this.log(
commandObj.log(
`Key-pair with name ${color.yellow(
keyPairName,
)} successfully removed from ${secretsConfigPath}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class Add extends BaseCommand<typeof Add> {

await serviceConfig.$commit();

this.log(
commandObj.log(
`Added ${color.yellow(moduleName)} to ${color.yellow(
replaceHomeDir(serviceConfig.$getPath()),
)}`,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/module/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const color = oclifColor.default;
import { Args, Flags } from "@oclif/core";

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { commandObj } from "../../lib/commandObj.js";
import { generateNewModule } from "../../lib/generateNewModule.js";
import { initCli } from "../../lib/lifeCycle.js";
import { ensureSrcModulesDir } from "../../lib/paths.js";
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class New extends BaseCommand<typeof New> {
const pathToModuleDir = join(pathToModulesDir, moduleName);
await generateNewModule(pathToModuleDir);

this.log(
commandObj.log(
`Successfully generated template for new module at ${color.yellow(
pathToModuleDir,
)}`,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/resource-owner/pat/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Args } from "@oclif/core";
const color = oclifColor.default;

import { BaseCommand, baseFlags } from "../../../baseCommand.js";
import { commandObj } from "../../../lib/commandObj.js";
import { NETWORK_FLAG, PRIV_KEY_FLAG } from "../../../lib/const.js";
import { initCli } from "../../../lib/lifeCycle.js";
import { input } from "../../../lib/prompt.js";
Expand Down Expand Up @@ -86,6 +87,6 @@ export default class CreatePAT extends BaseCommand<typeof CreatePAT> {
const patId: unknown = deal.interface.parseLog(log).args["id"];
assert(typeof patId === "string");

this.log(`PAT ID: ${color.yellow(patId)}`);
commandObj.log(`PAT ID: ${color.yellow(patId)}`);
}
}
2 changes: 2 additions & 0 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export default class Run extends BaseCommand<typeof Run> {
if (flags.quiet) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
commandObj.log = () => {};
// eslint-disable-next-line @typescript-eslint/no-empty-function
commandObj.logToStderr = () => {};
}

// if (typeof flags[ON_FLAG_NAME] === "string") {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/service/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Args, Flags } from "@oclif/core";

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { addService } from "../../lib/addService.js";
import { commandObj } from "../../lib/commandObj.js";
import { initNewReadonlyServiceConfig } from "../../lib/configs/project/service.js";
import { generateNewModule } from "../../lib/generateNewModule.js";
import {
Expand Down Expand Up @@ -87,7 +88,7 @@ export default class New extends BaseCommand<typeof New> {
serviceName,
);

this.log(
commandObj.log(
`Successfully generated template for new service at ${color.yellow(
servicePath,
)}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/service/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class Remove extends BaseCommand<typeof Remove> {

await fluenceConfig.$commit();

this.log(
commandObj.log(
`Removed service ${color.yellow(nameOrPathOrUrl)} from ${color.yellow(
fluenceConfig.$getPath(),
)}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/service/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class REPL extends Command {

const mreplPath = join(mreplDirPath, BIN_DIR_NAME, "mrepl");

this.log(`${SEPARATOR}Execute ${color.yellow(
commandObj.logToStderr(`${SEPARATOR}Execute ${color.yellow(
"help",
)} inside repl to see available commands.
Current service <module_name> is: ${color.yellow(facadeModuleConfig.name)}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const resolveServiceInfos = async ({
fluenceConfig.services === undefined ||
Object.keys(fluenceConfig.services).length === 0
) {
commandObj.log(
commandObj.logToStderr(
`No services to build. Use ${color.yellow(
`${CLI_NAME} service add`,
)} command to add services to ${color.yellow(fluenceConfig.$getPath())}`,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/helpers/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const resolveDependencies = async (
if (versionToUse === projectDependencyOverrides[name]) {
assert(maybeFluenceConfig !== null);

commandObj.log(
commandObj.logToStderr(
color.yellow(
`Using version ${versionToUse} of ${name} defined at ${maybeFluenceConfig.$getPath()} instead of the recommended version ${defaultVersion}. You can reset it to the recommended version by running \`${CLI_NAME} dep r\``,
),
Expand All @@ -356,7 +356,7 @@ export const resolveDependencies = async (
if (versionToUse === userDependencyOverrides[name]) {
assert(userFluenceConfig !== null);

commandObj.log(
commandObj.logToStderr(
color.yellow(
`Using version ${versionToUse} of ${name} defined at ${userFluenceConfig.$getPath()} instead of the recommended version ${defaultVersion}. You may want to consider adding it to your project's ${FLUENCE_CONFIG_FILE_NAME}. You can reset it to the recommended version by running \`${CLI_NAME} dep r -g\``,
),
Expand All @@ -375,7 +375,7 @@ export const resolveDependencies = async (
) {
assert(userFluenceConfig !== null);

commandObj.log(
commandObj.logToStderr(
color.yellow(
`Using version ${version} of ${name} defined at ${userFluenceConfig.$getPath()}, you may want to consider adding it to your project's ${FLUENCE_CONFIG_FILE_NAME}`,
),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { commandObj } from "../commandObj.js";
const SPINNER = color.yellow("#");

export const startSpinner = (message: string) => {
commandObj.log(`${SPINNER} ${message}...`);
commandObj.logToStderr(`${SPINNER} ${message}...`);
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const init = async (options: InitArg = {}): Promise<FluenceConfig> => {
const workersConfig = await initNewWorkersConfig();
await ensureAquaFileWithWorkerInfo(workersConfig, fluenceConfig);

commandObj.log(
commandObj.logToStderr(
color.magentaBright(
`\nSuccessfully initialized ${CLI_NAME_FULL} project template at ${replaceHomeDir(
projectPath,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/jsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const initFluenceClient = async (
maybeFluenceConfig: FluenceConfig | null,
): Promise<void> => {
const relay = resolveRelay(maybeRelay, maybeFluenceConfig?.relays);
commandObj.log(`Connecting to: ${color.yellow(relay)}`);
commandObj.logToStderr(`Connecting to: ${color.yellow(relay)}`);
const keyPair = await getExistingKeyPair(keyPairName);

try {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/lifeCycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const handleFloxVersion = async (

const version = isOlderThanStable ? stableVersion : unstableVersion;

commandObj.log(
commandObj.logToStderr(
`${SEPARATOR}New ${color.yellow(
isOlderThanStable ? "stable" : "unstable",
)} version ${color.yellow(
Expand All @@ -263,7 +263,7 @@ const handleFloxVersion = async (
userConfig.lastCheckForUpdates = CHECK_FOR_UPDATES_DISABLED;
await userConfig.$commit();

commandObj.log(
commandObj.logToStderr(
`\nUpdates checking is now disabled. You can enable it again by removing 'lastCheckForUpdates' property from ${userConfig.$getPath()}\n`,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/localServices/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const dagUpload = async (
export const doRegisterIpfsClient = (offAquaLogs: boolean): void => {
const log = (msg: unknown) => {
if (!offAquaLogs) {
commandObj.log(`ipfs: ${stringifyUnknown(msg)}`);
commandObj.logToStderr(`ipfs: ${stringifyUnknown(msg)}`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const getWalletConnectProvider = async (
url.searchParams.set(RELAY_QUERY_PARAM_NAME, bridge);
url.searchParams.set(KEY_QUERY_PARAM_NAME, key);

commandObj.log(
commandObj.logToStderr(
`To approve transactions to your wallet using metamask, open the following url:\n\n${url.toString()}\n\nor go to ${CLI_CONNECTOR_URL} and enter the following connection string there:\n\n${uri}\n`,
);
});
Expand Down Expand Up @@ -254,6 +254,6 @@ export const waitTx = async (

export const promptConfirmTx = (privKey: string | undefined) => {
if (privKey === undefined) {
commandObj.log(`Confirm transaction in your wallet...`);
commandObj.logToStderr(`Confirm transaction in your wallet...`);
}
};

0 comments on commit 6156b56

Please sign in to comment.