Skip to content

Commit

Permalink
fix(cli): lint fix (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahlitvin authored Dec 27, 2024
1 parent e43b388 commit dd373ae
Showing 1 changed file with 71 additions and 64 deletions.
135 changes: 71 additions & 64 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function configureRun(program: Command) {
return applyCommandsConfig(program, commandsConfig.run).action(async function (
packages: PackageSpecification[],
options,
program,
program
) {
log(bold('Starting local node...\n'));

Expand Down Expand Up @@ -258,67 +258,74 @@ applyCommandsConfig(program.command('verify'), commandsConfig.verify).action(asy
await verify(fullPackageRef, cliSettings, chainId);
});

applyCommandsConfig(program.command('diff'), commandsConfig.diff).action(
async function (packageRef, projectDirectory, options) {
const { diff } = await import('./commands/diff');
applyCommandsConfig(program.command('diff'), commandsConfig.diff).action(async function (
packageRef,
projectDirectory,
options
) {
const { diff } = await import('./commands/diff');

const cliSettings = resolveCliSettings(options);
const { fullPackageRef, chainId } = await getPackageInfo(packageRef, options.chainId, cliSettings.rpcUrl);

const foundDiffs = await diff(
fullPackageRef,
cliSettings,
chainId,
projectDirectory,
options.matchContract,
options.matchSource,
);
const cliSettings = resolveCliSettings(options);
const { fullPackageRef, chainId } = await getPackageInfo(packageRef, options.chainId, cliSettings.rpcUrl);

// exit code is the number of differences found--useful for CI checks
process.exit(foundDiffs);
},
);
const foundDiffs = await diff(
fullPackageRef,
cliSettings,
chainId,
projectDirectory,
options.matchContract,
options.matchSource
);

applyCommandsConfig(program.command('alter'), commandsConfig.alter).action(
async function (packageName, command, options, flags) {
const { alter } = await import('./commands/alter');
// exit code is the number of differences found--useful for CI checks
process.exit(foundDiffs);
});

const cliSettings = resolveCliSettings(flags);
applyCommandsConfig(program.command('alter'), commandsConfig.alter).action(async function (
packageName,
command,
options,
flags
) {
const { alter } = await import('./commands/alter');

// throw an error if the chainId is not consistent with the provider's chainId
await ensureChainIdConsistency(cliSettings.rpcUrl, flags.chainId);

// note: for command below, pkgInfo is empty because forge currently supplies no package.json or anything similar
const newUrl = await alter(
packageName,
flags.subpkg ? flags.subpkg.split(',') : [],
parseInt(flags.chainId),
cliSettings,
{},
command,
options,
{},
);
const cliSettings = resolveCliSettings(flags);

log(newUrl);
},
);
// throw an error if the chainId is not consistent with the provider's chainId
await ensureChainIdConsistency(cliSettings.rpcUrl, flags.chainId);

applyCommandsConfig(program.command('fetch'), commandsConfig.fetch).action(
async function (packageRef, givenIpfsUrl, options) {
const { fetch } = await import('./commands/fetch');
// note: for command below, pkgInfo is empty because forge currently supplies no package.json or anything similar
const newUrl = await alter(
packageName,
flags.subpkg ? flags.subpkg.split(',') : [],
parseInt(flags.chainId),
cliSettings,
{},
command,
options,
{}
);

const { fullPackageRef, chainId } = await getPackageReference(packageRef, options.chainId);
const ipfsUrl = getIpfsUrl(givenIpfsUrl);
const metaIpfsUrl = getIpfsUrl(options.metaHash) || undefined;
log(newUrl);
});

if (!ipfsUrl) {
throw new Error('IPFS URL is required.');
}
applyCommandsConfig(program.command('fetch'), commandsConfig.fetch).action(async function (
packageRef,
givenIpfsUrl,
options
) {
const { fetch } = await import('./commands/fetch');

const { fullPackageRef, chainId } = await getPackageReference(packageRef, options.chainId);
const ipfsUrl = getIpfsUrl(givenIpfsUrl);
const metaIpfsUrl = getIpfsUrl(options.metaHash) || undefined;

await fetch(fullPackageRef, chainId, ipfsUrl, metaIpfsUrl);
},
);
if (!ipfsUrl) {
throw new Error('IPFS URL is required.');
}

await fetch(fullPackageRef, chainId, ipfsUrl, metaIpfsUrl);
});

applyCommandsConfig(program.command('pin'), commandsConfig.pin).action(async function (packageRef, options) {
const cliSettings = resolveCliSettings(options);
Expand All @@ -344,7 +351,7 @@ applyCommandsConfig(program.command('pin'), commandsConfig.pin).action(async fun

applyCommandsConfig(program.command('publish'), commandsConfig.publish).action(async function (
packageRef,
options: { [opt: string]: string },
options: { [opt: string]: string }
) {
const { publish } = await import('./commands/publish');

Expand Down Expand Up @@ -421,8 +428,8 @@ applyCommandsConfig(program.command('publish'), commandsConfig.publish).action(a
log();
log(
gray(
`Package "${pkgRef.name}" not yet registered, please use "cannon register" to register your package first.\nYou need enough gas on Ethereum Mainnet to register the package on Cannon Registry`,
),
`Package "${pkgRef.name}" not yet registered, please use "cannon register" to register your package first.\nYou need enough gas on Ethereum Mainnet to register the package on Cannon Registry`
)
);
log();

Expand Down Expand Up @@ -475,7 +482,7 @@ applyCommandsConfig(program.command('publish'), commandsConfig.publish).action(a
}\n - Max Priority Fee Per Gas: ${
overrides.maxPriorityFeePerGas ? overrides.maxPriorityFeePerGas.toString() : 'default'
}\n - Gas Limit: ${overrides.gasLimit ? overrides.gasLimit : 'default'}\n` +
" - To alter these settings use the parameters '--max-fee-per-gas', '--max-priority-fee-per-gas', '--gas-limit'.\n",
" - To alter these settings use the parameters '--max-fee-per-gas', '--max-priority-fee-per-gas', '--gas-limit'.\n"
);

await publish({
Expand Down Expand Up @@ -527,7 +534,7 @@ applyCommandsConfig(program.command('inspect'), commandsConfig.inspect).action(a
chainId,
options.json ? 'json' : options.out,
options.writeDeployments,
options.sources,
options.sources
);
});

Expand All @@ -548,7 +555,7 @@ applyCommandsConfig(program.command('prune'), commandsConfig.prune).action(async
storage,
options.filterPackage?.split(',') || '',
options.filterVariant?.split(',') || '',
options.keepAge,
options.keepAge
);

if (pruneUrls.length) {
Expand Down Expand Up @@ -635,9 +642,9 @@ applyCommandsConfig(program.command('test'), commandsConfig.test).action(async f
warn(
yellowBright(
bold(
'⚠️ The `--` syntax for passing options to forge or anvil is deprecated. Please use `--forge.*` or `--anvil.*` instead.',
),
),
'⚠️ The `--` syntax for passing options to forge or anvil is deprecated. Please use `--forge.*` or `--anvil.*` instead.'
)
)
);
log();
}
Expand Down Expand Up @@ -702,22 +709,22 @@ applyCommandsConfig(program.command('interact'), commandsConfig.interact).action
priorityGasFee: options.maxPriorityFee,
},
resolver,
getMainLoader(cliSettings),
getMainLoader(cliSettings)
);

const deployData = await runtime.readDeploy(fullPackageRef, runtime.chainId);

if (!deployData) {
throw new Error(
`deployment not found for package: ${fullPackageRef} with chaindId ${chainId}. please make sure it exists for the given preset and current network.`,
`deployment not found for package: ${fullPackageRef} with chaindId ${chainId}. please make sure it exists for the given preset and current network.`
);
}

const outputs = await getOutputs(runtime, new ChainDefinition(deployData.def), deployData.state);

if (!outputs) {
throw new Error(
`no cannon build found for ${fullPackageRef} with chaindId ${chainId}. Did you mean to run the package instead?`,
`no cannon build found for ${fullPackageRef} with chaindId ${chainId}. Did you mean to run the package instead?`
);
}

Expand Down

0 comments on commit dd373ae

Please sign in to comment.