Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reuse command types/utils across packages #6441

Merged
merged 10 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/docsgen/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliOptionDefinition, CliCommand, CliExample, CliCommandOptions} from "../src/util/index.js";
import {CliOptionDefinition, CliCommand, CliExample, CliCommandOptions} from "@lodestar/utils";
import {toKebab} from "./changeCase.js";

const DEFAULT_SEPARATOR = "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
import yargs from "yargs";
import {hideBin} from "yargs/helpers";
import {registerCommandToYargs} from "@lodestar/utils";
import {cmds} from "./cmds/index.js";
import {globalOptions, rcConfigOption} from "./options/index.js";
import {registerCommandToYargs} from "./util/index.js";
import {getVersionData} from "./util/version.js";

const {version} = getVersionData();
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/beacon/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand, CliCommandOptions} from "../../util/index.js";
import {CliCommand, CliCommandOptions} from "@lodestar/utils";
import {GlobalArgs} from "../../options/index.js";
import {beaconOptions, BeaconArgs} from "./options.js";
import {beaconHandler} from "./handler.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/beacon/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils";
import {beaconNodeOptions, paramsOptions, BeaconNodeArgs} from "../../options/index.js";
import {LogArgs, logOptions} from "../../options/logOptions.js";
import {CliCommandOptions, CliOptionDefinition} from "../../util/index.js";
import {defaultBeaconPaths, BeaconPaths} from "./paths.js";

type BeaconExtraArgs = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/bootnode/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand, CliCommandOptions} from "../../util/index.js";
import {CliCommand, CliCommandOptions} from "@lodestar/utils";
import {GlobalArgs} from "../../options/index.js";
import {bootnodeOptions, BootnodeArgs} from "./options.js";
import {bootnodeHandler} from "./handler.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/bootnode/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CliOptionDefinition, CliCommandOptions} from "@lodestar/utils";
import {LogArgs, logOptions} from "../../options/logOptions.js";
import {CliOptionDefinition, CliCommandOptions} from "../../util/index.js";
import {MetricsArgs, options as metricsOptions} from "../../options/beaconNodeOptions/metrics.js";
import {defaultListenAddress, defaultP2pPort, defaultP2pPort6} from "../../options/beaconNodeOptions/network.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand, CliCommandOptions} from "../../util/index.js";
import {CliCommand, CliCommandOptions} from "@lodestar/utils";
import {GlobalArgs} from "../../options/index.js";
import {devOptions, IDevArgs} from "./options.js";
import {devHandler} from "./handler.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/dev/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommandOptions, CliOptionDefinition} from "../../util/index.js";
import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils";
import {beaconOptions, BeaconArgs} from "../beacon/options.js";
import {NetworkName} from "../../networks/index.js";
import {beaconNodeOptions, globalOptions} from "../../options/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {GlobalArgs} from "../options/index.js";
import {beacon} from "./beacon/index.js";
import {dev} from "./dev/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/lightclient/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {GlobalArgs} from "../../options/index.js";
import {ILightClientArgs, lightclientOptions} from "./options.js";
import {lightclientHandler} from "./handler.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/lightclient/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CliCommandOptions} from "@lodestar/utils";
import {LogArgs, logOptions} from "../../options/logOptions.js";
import {CliCommandOptions} from "../../util/index.js";

export type ILightClientArgs = LogArgs & {
beaconApiUrl?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/cmds/validator/blsToExecutionChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {DOMAIN_BLS_TO_EXECUTION_CHANGE, ForkName} from "@lodestar/params";
import {createBeaconConfig} from "@lodestar/config";
import {ssz, capella} from "@lodestar/types";
import {ApiError, getClient} from "@lodestar/api";
import {CliCommand} from "@lodestar/utils";

import {CliCommand, YargsError} from "../../util/index.js";
import {YargsError} from "../../util/index.js";
import {GlobalArgs} from "../../options/index.js";
import {getBeaconConfigFromArgs} from "../../config/index.js";
import {IValidatorCliArgs} from "./options.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/cmds/validator/import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import {Keystore} from "@chainsafe/bls-keystore";
import {YargsError, CliCommand, getPubkeyHexFromKeystore} from "../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {YargsError, getPubkeyHexFromKeystore} from "../../util/index.js";
import {getBeaconConfigFromArgs} from "../../config/beaconParams.js";
import {GlobalArgs} from "../../options/index.js";
import {validatorOptions, IValidatorCliArgs} from "./options.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/validator/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {GlobalArgs} from "../../options/index.js";
import {getAccountPaths} from "./paths.js";
import {slashingProtection} from "./slashingProtection/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/validator/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {getBeaconConfigFromArgs} from "../../config/beaconParams.js";
import {GlobalArgs} from "../../options/index.js";
import {IValidatorCliArgs} from "./options.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {defaultOptions} from "@lodestar/validator";
import {CliCommandOptions} from "@lodestar/utils";
import {LogArgs, logOptions} from "../../options/logOptions.js";
import {ensure0xPrefix, CliCommandOptions} from "../../util/index.js";
import {ensure0xPrefix} from "../../util/index.js";
import {keymanagerRestApiServerOptsDefault} from "./keymanager/server.js";
import {defaultAccountPaths, defaultValidatorPaths} from "./paths.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import path from "node:path";
import {toHexString} from "@chainsafe/ssz";
import {InterchangeFormatVersion} from "@lodestar/validator";
import {getNodeLogger} from "@lodestar/logger/node";
import {CliCommand, YargsError, ensure0xPrefix, isValidatePubkeyHex, writeFile600Perm} from "../../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {YargsError, ensure0xPrefix, isValidatePubkeyHex, writeFile600Perm} from "../../../util/index.js";
import {parseLoggerArgs} from "../../../util/logger.js";
import {GlobalArgs} from "../../../options/index.js";
import {LogArgs} from "../../../options/logOptions.js";
Expand All @@ -13,7 +14,7 @@ import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js";
import {ISlashingProtectionArgs} from "./options.js";

type ExportArgs = {
file?: string;
file: string;
pubkeys?: string[];
};

Expand Down Expand Up @@ -51,7 +52,6 @@ export const exportCmd: CliCommand<ExportArgs, ISlashingProtectionArgs & Account

handler: async (args) => {
const {file} = args;
if (!file) throw new YargsError("must provide file arg");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demandOption: true already ensures that a file arg is provided


const {config, network} = getBeaconConfigFromArgs(args);
const validatorPaths = getValidatorPaths(args, network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import fs from "node:fs";
import path from "node:path";
import {Interchange} from "@lodestar/validator";
import {getNodeLogger} from "@lodestar/logger/node";
import {CliCommand, YargsError} from "../../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {YargsError} from "../../../util/index.js";
import {parseLoggerArgs} from "../../../util/logger.js";
import {GlobalArgs} from "../../../options/index.js";
import {LogArgs} from "../../../options/logOptions.js";
Expand All @@ -13,7 +14,7 @@ import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js";
import {ISlashingProtectionArgs} from "./options.js";

type ImportArgs = {
file?: string;
file: string;
};

export const importCmd: CliCommand<ImportArgs, ISlashingProtectionArgs & AccountValidatorArgs & GlobalArgs & LogArgs> =
Expand All @@ -39,7 +40,6 @@ export const importCmd: CliCommand<ImportArgs, ISlashingProtectionArgs & Account

handler: async (args) => {
const {file} = args;
if (!file) throw new YargsError("must provide file arg");

const {config, network} = getBeaconConfigFromArgs(args);
const validatorPaths = getValidatorPaths(args, network);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../../../util/index.js";
import {CliCommand} from "@lodestar/utils";
import {AccountValidatorArgs} from "../options.js";
import {ISlashingProtectionArgs, slashingProtectionOptions} from "./options.js";
import {importCmd} from "./import.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommandOptions} from "../../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";
import {IValidatorCliArgs, validatorOptions} from "../options.js";

export type ISlashingProtectionArgs = Pick<IValidatorCliArgs, "beaconNodes"> & {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cmds/validator/voluntaryExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from "@lodestar/state-transition";
import {createBeaconConfig, BeaconConfig} from "@lodestar/config";
import {phase0, ssz, ValidatorIndex, Epoch} from "@lodestar/types";
import {toHex} from "@lodestar/utils";
import {CliCommand, toHex} from "@lodestar/utils";
import {externalSignerPostSignature, SignableMessageType, Signer, SignerType} from "@lodestar/validator";
import {Api, ApiError, getClient} from "@lodestar/api";
import {CliCommand, ensure0xPrefix, YargsError, wrapError} from "../../util/index.js";
import {ensure0xPrefix, YargsError, wrapError} from "../../util/index.js";
import {GlobalArgs} from "../../options/index.js";
import {getBeaconConfigFromArgs} from "../../config/index.js";
import {IValidatorCliArgs} from "./options.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defaultOptions, IBeaconNodeOptions, allNamespaces} from "@lodestar/beacon-node";
import {CliCommandOptions} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";

const enabledAll = "*";

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/beaconNodeOptions/builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {defaultExecutionBuilderHttpOpts, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions, YargsError} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";
import {YargsError} from "../../util/index.js";

export type ExecutionBuilderArgs = {
builder: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/chain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "node:path";
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";

export type ChainArgs = {
suggestedFeeRecipient: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/beaconNodeOptions/eth1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions, extractJwtHexSecret} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";
import {extractJwtHexSecret} from "../../util/index.js";
import {ExecutionEngineArgs} from "./execution.js";

export type Eth1Args = {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/beaconNodeOptions/execution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import {defaultExecutionEngineHttpOpts, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions, extractJwtHexSecret} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";
import {extractJwtHexSecret} from "../../util/index.js";

export type ExecutionEngineArgs = {
"execution.urls": string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";

export type MetricsArgs = {
metrics: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/monitoring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";

export type MonitoringArgs = {
"monitoring.endpoint"?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/beaconNodeOptions/network.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {multiaddr} from "@multiformats/multiaddr";
import {ENR} from "@chainsafe/enr";
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions, YargsError} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";
import {YargsError} from "../../util/index.js";

export const defaultListenAddress = "0.0.0.0";
export const defaultP2pPort = 9000;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node";
import {CliCommandOptions} from "../../util/index.js";
import {CliCommandOptions} from "@lodestar/utils";

export type SyncArgs = {
"sync.isSingleNode"?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/globalOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ACTIVE_PRESET} from "@lodestar/params";
import {CliCommandOptions} from "@lodestar/utils";
import {NetworkName, networkNames} from "../networks/index.js";
import {CliCommandOptions, readFile} from "../util/index.js";
import {readFile} from "../util/index.js";
import {paramsOptions, IParamsArgs} from "./paramsOptions.js";

type GlobalSingleArgs = {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/options/logOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {LogLevels} from "@lodestar/utils";
import {LogLevels, CliCommandOptions} from "@lodestar/utils";
import {LogLevel, logFormats} from "@lodestar/logger";
import {CliCommandOptions} from "../util/command.js";
import {LOG_FILE_DISABLE_KEYWORD} from "../util/logger.js";

export type LogArgs = {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/options/paramsOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ChainConfig, chainConfigTypes} from "@lodestar/config";
import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils";
import {IBeaconParamsUnparsed} from "../config/types.js";
import {ObjectKeys, CliCommandOptions, CliOptionDefinition} from "../util/index.js";
import {ObjectKeys} from "../util/index.js";

// No options are statically declared
// If an arbitrary key notation is used, it removes type safety on most of this CLI arg parsing code.
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./command.js";
export * from "./errors.js";
export * from "./ethers.js";
export * from "./file.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/flare/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
import yargs from "yargs";
import {hideBin} from "yargs/helpers";
import {registerCommandToYargs} from "@lodestar/utils";
import {cmds} from "./cmds/index.js";
import {registerCommandToYargs} from "./util/command.js";

const topBanner = `Beacon chain multi-purpose and debugging tool.

Expand Down
2 changes: 1 addition & 1 deletion packages/flare/src/cmds/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliCommand} from "../util/command.js";
import {CliCommand} from "@lodestar/utils";
import {selfSlashProposer} from "./selfSlashProposer.js";
import {selfSlashAttester} from "./selfSlashAttester.js";

Expand Down
3 changes: 1 addition & 2 deletions packages/flare/src/cmds/selfSlashAttester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {phase0, ssz} from "@lodestar/types";
import {config as chainConfig} from "@lodestar/config/default";
import {createBeaconConfig, BeaconConfig} from "@lodestar/config";
import {DOMAIN_BEACON_ATTESTER, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
import {toHexString} from "@lodestar/utils";
import {CliCommand, toHexString} from "@lodestar/utils";
import {computeSigningRoot} from "@lodestar/state-transition";
import {CliCommand} from "../util/command.js";
import {deriveSecretKeys, SecretKeysArgs, secretKeysOptions} from "../util/deriveSecretKeys.js";

/* eslint-disable no-console */
Expand Down
3 changes: 1 addition & 2 deletions packages/flare/src/cmds/selfSlashProposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {phase0, ssz} from "@lodestar/types";
import {config as chainConfig} from "@lodestar/config/default";
import {createBeaconConfig, BeaconConfig} from "@lodestar/config";
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
import {toHexString} from "@lodestar/utils";
import {CliCommand, toHexString} from "@lodestar/utils";
import {computeSigningRoot} from "@lodestar/state-transition";
import {CliCommand} from "../util/command.js";
import {deriveSecretKeys, SecretKeysArgs, secretKeysOptions} from "../util/deriveSecretKeys.js";

/* eslint-disable no-console */
Expand Down
53 changes: 0 additions & 53 deletions packages/flare/src/util/command.ts

This file was deleted.

Loading
Loading