Skip to content

Commit aca18a3

Browse files
committed
chore: add a confirmation step before deploying from CLI
1 parent 5865b14 commit aca18a3

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

cli/commands/deploy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ import {
99
} from '../network'
1010
import { loadEnv, CLIArgs, CLIEnvironment } from '../env'
1111
import { logger } from '../logging'
12+
import { confirm } from '../helpers'
1213

1314
export const deploy = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
1415
const contractName = cliArgs.contract
1516
const initArgs = cliArgs.init
1617
const deployType = cliArgs.type
1718
const buildAcceptProxyTx = cliArgs.buildTx
1819

20+
// Ensure action
21+
const sure = await confirm(`Are you sure to deploy ${contractName}?`)
22+
if (!sure) return
23+
1924
// Deploy contract
2025
const contractArgs = initArgs ? initArgs.split(',') : []
2126
switch (deployType) {

cli/commands/proxy/admin.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import inquirer from 'inquirer'
21
import yargs, { Argv } from 'yargs'
32

43
import { logger } from '../../logging'
54
import { getContractAt, sendTransaction } from '../../network'
65
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
6+
import { confirm } from '../../helpers'
77

88
export const setProxyAdmin = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
99
const contractName = cliArgs.contract
@@ -12,13 +12,8 @@ export const setProxyAdmin = async (cli: CLIEnvironment, cliArgs: CLIArgs): Prom
1212
logger.info(`Set proxy admin for contract ${contractName} to ${adminAddress}`)
1313

1414
// Warn about changing ownership
15-
const res = await inquirer.prompt({
16-
name: 'confirm',
17-
type: 'confirm',
18-
message: `Are you sure to set the admin to ${adminAddress}?`,
19-
})
20-
if (!res.confirm) {
21-
logger.info('Cancelled')
15+
const sure = await confirm(`Are you sure to set the admin to ${adminAddress}?`)
16+
if (!sure) {
2217
return
2318
}
2419

cli/helpers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as dotenv from 'dotenv'
33

44
import { utils, providers, Wallet } from 'ethers'
55
import ipfsHttpClient from 'ipfs-http-client'
6+
import inquirer from 'inquirer'
67

78
import * as bs58 from 'bs58'
89

@@ -89,3 +90,16 @@ export const pinMetadataToIPFS = async (
8990
logger.info(`Upload metadata successful: ${metaHash}\n`)
9091
return IPFS.ipfsHashToBytes32(metaHash)
9192
}
93+
94+
export const confirm = async (message: string): Promise<boolean> => {
95+
const res = await inquirer.prompt({
96+
name: 'confirm',
97+
type: 'confirm',
98+
message,
99+
})
100+
if (!res.confirm) {
101+
logger.info('Cancelled')
102+
return false
103+
}
104+
return true
105+
}

0 commit comments

Comments
 (0)