-
Notifications
You must be signed in to change notification settings - Fork 0
Config and Defaults #14
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
Conversation
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughThis change refactors configuration, context, and command inheritance for a CLI application. It enforces stricter keypair requirements for transaction commands, updates context and signer initialization logic, modifies command base classes, and adjusts storage provider initialization. Several files receive import cleanups and script/configuration tweaks, without altering core command logic. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLICommand
participant TransactionCommand
participant Context
participant Signer
User->>CLICommand: invoke command
CLICommand->>TransactionCommand: init()
TransactionCommand->>Context: createContext(configPath, overrides, transactionContext=true)
Context->>Context: resolve config path and load config
Context->>Context: enforce keypair presence if transactionContext
Context->>Signer: createSignerFromPath(keypairPath)
Context-->>TransactionCommand: return context (with signer, config, etc.)
TransactionCommand-->>CLICommand: proceed with command logic
Possibly related PRs
Suggested reviewers
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (19)
package.json
(1 hunks)src/TransactionCommand.ts
(1 hunks)src/commands/core/asset/burn.ts
(2 hunks)src/commands/core/asset/create.ts
(1 hunks)src/commands/core/asset/fetch.ts
(2 hunks)src/commands/core/asset/index.ts
(1 hunks)src/commands/core/asset/template.ts
(1 hunks)src/commands/core/asset/update.ts
(2 hunks)src/commands/core/collection/create.ts
(1 hunks)src/commands/core/collection/fetch.ts
(0 hunks)src/commands/core/collection/template.ts
(1 hunks)src/commands/core/plugins/generate.ts
(1 hunks)src/commands/core/plugins/index.ts
(1 hunks)src/commands/toolbox/rent.ts
(1 hunks)src/commands/toolbox/token/transfer.ts
(1 hunks)src/commands/toolbox/token/update.ts
(1 hunks)src/lib/Context.ts
(7 hunks)src/lib/uploader/initStorageProvider.ts
(1 hunks)src/lib/uploader/uploadProviders/irys.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- src/commands/core/collection/fetch.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/TransactionCommand.ts (1)
src/lib/Context.ts (1)
createContext
(150-190)
src/lib/uploader/initStorageProvider.ts (1)
src/lib/Context.ts (1)
ConfigJson
(25-44)
src/lib/Context.ts (1)
src/lib/util.ts (1)
DUMMY_UMI
(35-35)
🪛 Biome (1.9.4)
src/lib/Context.ts
[error] 116-116: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 150-150: This type annotation is trivially inferred from its initialization.
Safe fix: Remove the type annotation.
(lint/style/noInferrableTypes)
[error] 168-168: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 183-183: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 185-185: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
🔇 Additional comments (18)
src/commands/core/plugins/generate.ts (2)
1-1
: Cleanup of unused importsThe unnecessary
Args
import has been removed, keeping only theFlags
import that's actually used in the code.
6-7
: Import order reorganizationThe imports from plugin-related files have been reordered. While this change is cosmetic, it contributes to better code organization.
package.json (1)
20-21
: CLI configuration improvementsThese changes enhance the oclif CLI configuration:
- Fixed the syntax for
topicSeparator
property- Added
"dirname": "mplx"
to specify the CLI directory nameThese updates align with the PR objective of standardizing configuration file locations and support the consistent CLI structure.
src/commands/core/asset/index.ts (1)
1-1
: Removed unused importsThe import statement has been simplified by removing unused
Args
andFlags
imports, keeping only the necessaryCommand
import. This is part of a broader cleanup effort seen across the codebase.src/commands/core/asset/create.ts (1)
8-8
: Import reorderingThe import for explorer-related utilities has been moved up in the import list. While this is a cosmetic change, it contributes to more consistent import organization across the codebase.
src/commands/core/collection/template.ts (1)
1-4
: Import cleanup looks goodThe import statements have been cleaned up by removing the unused
Flags
import and reordering imports. This makes the code cleaner without affecting functionality.src/commands/core/asset/template.ts (1)
1-7
: Import reorganization looks goodThe imports have been cleaned up by removing unused imports and reordering them. This improves code readability without changing functionality.
src/commands/core/asset/update.ts (1)
11-11
: Base class change aligns with transaction validation improvementsChanged from
BaseCommand
toTransactionCommand
which is appropriate since this is a transaction-based command that requires keypair validation. This change aligns with the PR objective of enforcing the presence of a keypair for transaction commands.This change ties into the broader improvement of enforcing proper keypair context for commands that interact with the blockchain.
Also applies to: 30-30
src/commands/core/asset/fetch.ts (1)
7-7
: Base class change is appropriateChanged from
TransactionCommand
toBaseCommand
since fetching assets is a read-only operation that doesn't require transaction signing. This properly differentiates between commands that need transaction context and those that don't.This change is consistent with the PR's goal of distinguishing between transaction and non-transaction commands, applying stricter keypair validation only where needed.
Also applies to: 21-21
src/commands/toolbox/token/update.ts (1)
11-17
: Documentation simplification looks good.The comment block has been simplified to be more general rather than listing specific update options, making the documentation more maintainable while still conveying the essential information.
src/commands/core/asset/burn.ts (1)
15-15
: Appropriate inheritance change for transaction command.The class now correctly extends
TransactionCommand
instead ofBaseCommand
, which enforces keypair validation for transaction operations. This is aligned with the PR objective of requiring keypairs for transaction commands.Also applies to: 56-56
src/TransactionCommand.ts (1)
99-108
: Good implementation of transaction context enforcement.Setting
transactionContext
totrue
ensures that all commands extendingTransactionCommand
will require a keypair to be specified, preventing accidental use of dummy signers. This change properly implements the PR objective for transaction command keypair validation.src/commands/core/plugins/index.ts (1)
1-4
: Command inheritance standardization looks good.Changing the base class from
Command
toBaseCommand<typeof CorePlugins>
is consistent with the standardization of command inheritance across the codebase. Since this command doesn't perform transactions, usingBaseCommand
is the appropriate choice.src/commands/core/collection/create.ts (1)
12-14
: LGTM on command class inheritance changeThe change from
BaseCommand
toTransactionCommand
aligns with the PR objective to enforce keypair validation for transaction commands. Since this command creates collections on-chain, it requires a keypair for signing, making this inheritance change appropriate.src/commands/toolbox/token/transfer.ts (1)
1-8
: Clean import organization improvementThe imports have been reorganized for better clarity:
- Removed unused
Flags
import- Consolidated imports from
mpl-toolbox
to only include used functions- Improved logical grouping of imports
This enhances code maintainability without changing functionality.
src/lib/uploader/uploadProviders/irys.ts (1)
3-5
: Simplified uploader initialization properly decouples dependenciesRemoving the
Umi
parameter frominitIrysUploader
simplifies the function and aligns with the PR objective to fix uploader configuration. This makes the initialization more flexible and properly passes options directly to the underlyingirysUploader
.src/commands/toolbox/rent.ts (1)
4-27
: Appropriate command class refactoringChanging
ToolboxRent
to extendBaseCommand
instead ofTransactionCommand
is appropriate since this command only retrieves rent costs and doesn't require transaction signing. This aligns with the PR's command inheritance restructuring where commands are properly categorized based on their transaction requirements.The code formatting improvements maintain the same behavior while enhancing readability.
src/lib/Context.ts (1)
168-170
: Avoid non-null assertions – surface configuration errors earlyUsing
config.rpcUrl!
,config.commitment!
, and laterconfig.explorer || …
hides the possibility that these values are actuallyundefined
.
Consider:
- Supplying defaults directly in
DEFAULT_CONFIG
(they mostly exist already).- Narrowing the type after consolidation so non-null assertions are
unnecessary.Also applies to: 183-185
🧰 Tools
🪛 Biome (1.9.4)
[error] 168-168: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 169-169: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (3)
src/lib/Context.ts (3)
23-23
: 🧹 Nitpick (assertive)Remove unused
abort
import
abort
is still imported but never referenced, leaving dead code behind.-import { abort } from 'node:process'
76-82
: 🛠️ Refactor suggestion
prefix
parameter remains unused ingetDefaultConfigPath
The parameter was called out in a previous review but is still unused, which can mislead future contributors.
-export const getDefaultConfigPath = (prefix: string): string => { +export const getDefaultConfigPath = (): string => {Alternatively, incorporate
prefix
into the returned path if that was the original intent.
116-117
: 🧹 Nitpick (assertive)Switch to template literal for clearer error message
Template literals are more readable and flagged by the linter.
- throw new Error('Keypair file not found at: ' + path + ' please check your config file or use the --keypair flag') + throw new Error( + `Keypair file not found at: ${path}. Please check your config file or use the --keypair flag.` + )🧰 Tools
🪛 Biome (1.9.4)
[error] 116-116: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/lib/Context.ts
(7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lib/Context.ts (1)
src/lib/util.ts (1)
DUMMY_UMI
(35-35)
🪛 Biome (1.9.4)
src/lib/Context.ts
[error] 116-116: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 150-150: This type annotation is trivially inferred from its initialization.
Safe fix: Remove the type annotation.
(lint/style/noInferrableTypes)
[error] 162-162: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 177-177: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 179-179: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
🔇 Additional comments (1)
src/lib/Context.ts (1)
58-63
: Good call setting a concrete default storage providerDefining the storage provider up-front (
irys
) keeps behaviour predictable across installs. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (5)
src/lib/uploader/initStorageProvider.ts (1)
8-11
: Redundant switch – collapse to single returnSince both
case 'irys'
anddefault
paths execute identical logic, the switch adds noise.
Previous reviews have already pointed this out. A straight return keeps the intent crystal-clear.- switch (storageConfig?.name) { - case 'irys': - default: - return initIrysUploader(storageConfig?.options) - } + // Irys is currently the sole provider – always initialise it + return initIrysUploader(storageConfig?.options)src/lib/Context.ts (4)
102-106
: Parameter should not acceptundefined
createSignerFromPath
throws ifpath
is falsy, so acceptingundefined
in the type signature misleads callers and forces a runtime check.
This was raised previously.
115-116
: Use template literals for clearer error messageString concatenation is harder to read and was already flagged.
150-152
: Avoid non-null assertions
config.rpcUrl!
andconfig.commitment!
repeat the non-null assertion anti-pattern highlighted earlier.
138-147
: 🧹 Nitpick (assertive)Condense signer selection logic
The branching can be simplified to a single expression, reducing duplication:
- let signer: Signer - if (isTransactionContext) { - signer = await createSignerFromPath(config.keypair) - } else { - signer = config.keypair ? await createSignerFromPath(config.keypair) : createNoopSigner() - } + const signer = (isTransactionContext || config.keypair) + ? await createSignerFromPath(config.keypair) + : createNoopSigner()This keeps the happy-path compact while preserving current behaviour.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (3)
src/TransactionCommand.ts
(2 hunks)src/lib/Context.ts
(7 hunks)src/lib/uploader/initStorageProvider.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/lib/uploader/initStorageProvider.ts (2)
Learnt from: tonyboylehub
PR: metaplex-foundation/cli#14
File: src/lib/uploader/initStorageProvider.ts:8-13
Timestamp: 2025-05-08T20:00:59.971Z
Learning: The Metaplex CLI currently only supports 'irys' as a storage provider, and the code is designed to default to Irys even when another provider name is specified.
Learnt from: tonyboylehub
PR: metaplex-foundation/cli#14
File: src/lib/uploader/initStorageProvider.ts:5-7
Timestamp: 2025-05-08T20:02:52.120Z
Learning: The `initStorageProvider` function in the Metaplex CLI is designed to always initialize a default Irys uploader, even when no storage configuration is provided. This is intentional behavior to ensure upload functionality is always available as a fallback.
🧬 Code Graph Analysis (3)
src/TransactionCommand.ts (1)
src/lib/Context.ts (2)
getDefaultConfigPath
(75-81)createContext
(138-172)
src/lib/uploader/initStorageProvider.ts (1)
src/lib/Context.ts (1)
ConfigJson
(24-43)
src/lib/Context.ts (1)
src/lib/util.ts (1)
DUMMY_UMI
(35-35)
🔇 Additional comments (2)
src/lib/Context.ts (2)
54-62
: Double-check defaultstorage.options
typing
IrysUploaderOptions
may allow an empty object, yet if the type later becomes stricter an implicit{}
will break compilation.
Safer to cast or explicitly mark asPartial<IrysUploaderOptions>
:- storage: { - name: 'irys' as const, - options: {}, - }, + storage: { + name: 'irys' as const, + options: {} as Partial<IrysUploaderOptions>, + },
75-81
: 👍 Robust cross-platform config locationThe helper now defers to
HOME
/USERPROFILE
andpath.join
, which fixes Windows path separators – nice improvement!
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
src/commands/toolbox/rent.ts (1)
22-24
:⚠️ Potential issueRemove duplicate
args
property.There's a duplicate definition of the
args
property. This one should be removed as it's identical to the one defined on lines 11-13.static override flags = { // Ignore the 128 byte header for the rent cost noHeader: Flags.boolean({ description: 'Ignore the 128 byte header for the rent cost', default: false }), // Flag to display the rent cost in Lamports lamports: Flags.boolean({ description: 'Display the rent cost in Lamports', default: false }), } - static override args = { - bytes: Args.integer({ description: 'Number of bytes', required: true }), - }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (1)
src/commands/toolbox/rent.ts
(2 hunks)
🔇 Additional comments (1)
src/commands/toolbox/rent.ts (1)
6-6
: Base class change fromTransactionCommand
toBaseCommand
.This change aligns with the PR objectives to refactor command inheritance patterns. The
ToolboxRent
command doesn't need transaction-specific functionality, so usingBaseCommand
is appropriate.
Fix conflict merge error.
Config File Location Standardization, Transaction Command Improvements, and Uploader Fixes
Major Changes
Config File Location Standardization
getDefaultConfigPath
to use a consistent config file location across all operating systemspath.join()
for cross-platform compatibility~/.config/mplx/config.json
across all platformsTransaction Command Keypair Validation
transactionContext
flag to enforce keypair requirements for transaction commandsUploader Configuration
DEFAULT_CONFIG
Technical Details
Config File Handling
process.env.HOME
for Unix-like systems (macOS/Linux)process.env.USERPROFILE
for Windowspath.join()
Config File Locations
/Users/<username>/.config/mplx/config.json
/home/<username>/.config/mplx/config.json
C:\Users\<username>\.config\mplx\config.json
Transaction Command Improvements
createContext
to check for keypair presenceUploader Improvements
DEFAULT_CONFIG
createContext
Benefits
Config File Standardization
--config
flag overrideTransaction Command Reliability
Uploader Reliability